forked from rohan-paul/Awesome-JavaScript-Interviews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtruthy-falsy-1.js
34 lines (26 loc) · 868 Bytes
/
truthy-falsy-1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
The following values are always falsy:
false
0 (zero)
'' or "" (empty string)
null
undefined
NaN
Everything else is truthy. That includes:
'0' (a string containing a single zero)
'false' (a string containing the text “false”)
[] (an empty array)
{} (an empty object)
function(){} (an “empty” function)
*/
// Check false is falsy
// false ? console.log("Truthy") : console.log("Falsy")
// Check 0 is falsy
// 0 ? console.log("Truthy") : console.log("Falsy")
// Check empty string is falsy
// "" ? console.log("Truthy") : console.log("Falsy")
null ? console.log("truthy") : console.log("falsy") // falsy
undefined ? console.log("truthy") : console.log("falsy") // falsy
false ? console.log("truthy") : console.log("falsy") // falsy
NaN ? console.log("truthy") : console.log("falsy") // falsy
"" ? console.log("truthy") : console.log("falsy") // falsy