Why do I get different outputs for this program after making them both equal? | Sololearn: Learn to code for FREE!
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);

9th Jul 2019, 3:45 PM
eMBee
eMBee - avatar
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
9th Jul 2019, 8:32 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 2
I answered this in one of your later questions :/
9th Jul 2019, 4:37 PM
Airree
Airree - avatar