[quote=“jgetner, post:8, topic:240030, full:true”]Since null is a primitive type object in javascript undefined and null are different in terms of how memory see’s them that is a great point.
[/quote]
How does that relate to the question at hand though?
When you do not provide a comparison, the condition checks to see if the boolean result is true or false.
if ($("#test").val()) { // Boolean("") equals false
...
}
In JavaScript, we talk of values being truthy or falsy, which speaks of what a value will be evaluated as when it is passed through a boolean condition.
Several types of values are considered to be falsy:
if (false)
if (null)
if (undefined)
if (0)
if (NaN)
if ('')
if ("")
Be wary though, for even though 0 and “” are falsy, “0” is not falsy as it contains a string character.
The double equals performs a loose equality comparison. Some loose equality charts have been created, but it can be difficult to fully understand the comparisons when coding.
For a good example, see the chart at http://dorey.github.io/JavaScript-Equality-Table/
http://www.jqueryscript.net/images/collective/Equality%20Table.jpg
Or for more complete details, see the chart at http://dorey.github.io/JavaScript-Equality-Table/unified/
Due to difficulties of remembering the above, it’s best to always use the triple-equals strict comparison instead, so that there is no doubt over what is being compared.