1

I'm studying Javascript and in one of my quizzes I found this

var foo = function(){}; 
console.log(foo === foo);  //  true 
console.log(foo === function(){});  // false 
console.log(function(){} === function(){});// false 
console.log(foo instanceof function(){}); // false 
console.log(['a'] == ['a']);// false 

Beside foo === function(){} and foo instanceof function(){} which are evidently false I can't get why all the other comparisons are also false. For example why ['a'] == ['a'] should be false?

Thank you in advance!

Lee Lennon
  • 31
  • 3
  • 1
    Because it is not the same object. Contents appear to be the same, but they are different objects. `var a = [1]; var b = [1]; console.log(a===a, a===b)` – epascarello Jan 04 '23 at 11:49
  • 1
    back to question what is being compared? if you compare like that, it will take all of its properties to compare..and you will get false, because its not a same object, like @epascarello said. you can try console.log( typeof function(){} === typeof function(){} ); that will given true, because it was same type.. – Hanna Rose Jan 04 '23 at 12:05

0 Answers0