I was explaining to a friend of mine the difference between ==
and ===
in PHP and wanted to demonstrate this through the javascript console.
I was going to show him that in PHP, the following sentences would return TRUE
when the comparison operator ==
was used.
So:
var_dump(1 == true); // TRUE
var_dump(2 == true); // TRUE
However, when I applied this to the console to exemplify with javascript, the result was this:
test1 = 1 == true;
test2 = 2 == true;
console.log(test1); // true
console.log(test2); // false
Update
When we instantiate Boolean
with these numbers, the results are different:
new Boolean(1); // true
new Boolean(2); // true
new Boolean(0); // false