0

What will be the output of the following code and why?

author
subina kallyani
easy
5
233
let a=[1,2,3];
let b=[1,2,3];
console.log(a==b);
console.log(a===b);
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 == bfalse because it compares references, not the content.
a === bfalse 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