let a=[1,2,3];
let b=[1,2,3];
console.log(a==b);
console.log(a===b);0
What will be the output of the following code and why?
subina kallyani
easy
5completed
233
Answer
Both lines will print false
In JavaScript, arrays are objects, and objects are compared by reference—not by their content. Even though a and b have the same elements, they are stored at different memory locations. So:a == b → false because it compares references, not the content.a === b → false because strict equality also compares references, and they are not the same object.
If both variables pointed to the same array, the result would be true for both.
Click to Reveal Answer
Tap anywhere to see the solution
Revealed
Comments0