Amit20 Posted September 14, 2011 Share Posted September 14, 2011 Hello Friends.... I was going through js tutorials online and now i have got this doubt; z = new Boolean(false); if(z) //Condition returns true i just want to know why the value of z evaluates to true and and when i alert the value of z it comes out to false. Plz Explain!!! Link to comment https://forums.phpfreaks.com/topic/247116-confused/ Share on other sites More sharing options...
Adam Posted September 14, 2011 Share Posted September 14, 2011 You're testing against the Boolean object itself, not the boolean value. The object contains a toString() method that returns the boolean value when you use it in a string context. Link to comment https://forums.phpfreaks.com/topic/247116-confused/#findComment-1269138 Share on other sites More sharing options...
Amit20 Posted September 14, 2011 Author Share Posted September 14, 2011 Thanks for reply. But while checking the value of z in if condition it evaluates to true. y??? Link to comment https://forums.phpfreaks.com/topic/247116-confused/#findComment-1269146 Share on other sites More sharing options...
Adam Posted September 14, 2011 Share Posted September 14, 2011 You're comparing an object, which will return true as it exists (and isn't null or undefined). Think of it more like this: if (object) { // object exists } Whereas a normal boolean comparison is: if (boolean) { // boolean is true } Link to comment https://forums.phpfreaks.com/topic/247116-confused/#findComment-1269147 Share on other sites More sharing options...
Amit20 Posted September 14, 2011 Author Share Posted September 14, 2011 Oh Got It!!! Thanks alot Link to comment https://forums.phpfreaks.com/topic/247116-confused/#findComment-1269149 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.