Skip navigation

Shocks

“false” is true  – check if(“false”) alert(true) 
“null” is true – check if(“null”) alert(true)
-1 is true – check if(-1) alert(true)
var x=”False”; if(x) alert(“true”);  is true
alert(true+1) is 2
alert(true==1) is true
alert(true===1) false
alert(false+1) is 1
alert(false==0) true
alert(false===0) false //false is not a number
if(2) alert(true); alerts true

Falsy

null
false
undefined
“” (empty string)
0 (zero)
NaN (not a number)

You can verify this by converting these values into boolean using Boolean

javascript:alert(Boolean(null));  //copy & paste at address bar 
javascript:alert(Boolean(“”)); 

Truthy

Infinity (3/0)
1 (Any number) 
any object including Array, empty or not 

Reference

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: