Javascript Object Question 1

Introduction

What is the output of the following code:

let myObj1 = {a:123,b:"hello"};
let myObj2 = {a:123,b:"hello"};   
let myObj3 = myObj1;

console.log(myObj1 == myObj2);    //  w w  w .  ja  v  a 2 s . c  o  m
console.log(myObj1 >= myObj2);    
console.log(myObj1 <= myObj2);    
console.log(myObj1 == myObj3);    

console.log(myObj1 == "[object Object]"); 


false
true
true
true
true

let myObj1 = {a:123,b:"hello"};
let myObj2 = {a:123,b:"hello"};    // Identical to the first object
let myObj3 = myObj1;

console.log(myObj1 == myObj2);    // false
console.log(myObj1 >= myObj2);    // false
console.log(myObj1 <= myObj2);    // false
console.log(myObj1 == myObj3);    // true because they share the same reference

console.log(myObj1 == "[object Object]");    // true on Mozilla



PreviousNext

Related