New course! Every coder should learn Generative AI!
Try a free lesson+ 3
Why do I get different outputs for this program after making them both equal?
var a = {a: 1}; var b = {a: 1}; console.log(a == b); console.log(a === b); var c = a; console.log(a == b); console.log(a === b);
2 Answers
+ 13
"==" checks only for equality in value whereas "===" is a stricter equality test and returns false if either the value or the type of the two variables are different.
So, the second option needs both the value and the type to be the same for the operands.
console.log( false == '0' ) // true
console.log( false === '0' ) // false
https://code.sololearn.com/W3CwqAGgJqRV/?ref=app
+ 2
I answered this in one of your later questions :/