-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path28_Truthy_FalseyValue.js
More file actions
50 lines (31 loc) · 1.12 KB
/
28_Truthy_FalseyValue.js
File metadata and controls
50 lines (31 loc) · 1.12 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
Falsy value : false he man liya jata hai
false , 0 , -0 ,BigInt 0n , ""(empty string " without space") , null , undefined , NaN
Truthy values : true he man liya jata hai : rest everything are considered as true
like --> "0" (0 is written inside the string here) ,
"false"
[] (empty array)
" " ( with space)
{} (empty object)
function(){} (empty function)
*/
const userEmail = "tarunsharma@gmail.com"
if(userEmail){
console.log("Got the user email")
}
else {
console.log("Dont have user email")
}
if ( "" ){ // does not run "" is considered false and if statement does not run false condition
console.log("falsy value")
}
// To check the object is empty
const abc = {} //empty object
if ( Object.keys(abc).length === 0 ){
console.log("the object is empty")
}
/* Object.keys(abc) --> this function will retun all the keys of the object in from of array.
Since here object is empty so the key array will also be empty [].
Now since the length of the empty array is 0 .
So Object.keys(abc).length will retun 0.
*/