Monday, November 12, 2012

Is {} == true or not in javascript?

Can someone explain why in javascript,


alert({} == true) shows false


if ({}) alert(\'true\') shows true ?


What\’s different in the if condition that changes the result?


I wanted to write some shorthand argument validator obj || (obj = {}); and I was baffled by this discovery.






Rating: 2 out of 5 based on 5 ratings



The post Is {} == true or not in javascript? appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/is-true-or-not-in-javascript.html

No comments:

Post a Comment