Comparison operators in JavaScript
Another pretty weird but some may argue powerful feature of JavaScript is the way it handles comparisons. In JavaScript, (false==0) , (null==undefined), (""==0) all result in TRUE! Weird? You bet it is! What JavaScript does behind the scene? It uses pretty confusing and complicated set of rules while comparing values. In most cases it just tries to convert one of the values to the type of the other value. However, when null or undefined occur, it only produces true if both sides are null or undefined. For cases where you do not want any automatic type conversions to happen, there are two extra operators: === and !==. The first tests whether a value is precisely equal to the other, and the second tests whether it is not precisely equal. So now, (false===0) , (null===undefined), (""===0) will all return false as expected! Amusing, isn't it? Reference: http://eloquentjavascript.net