JavaScript#3 · 4 Dec 2026
Same items, same array?
const a = [1, 2];
const b = [1, 2];
const c = a;
console.log(a === b);
console.log(a === c);
console.log(String(a) === String(b));What does this print?
JavaScript · Equality
const a = [1, 2];
const b = [1, 2];
const c = a;
console.log(a === b);
console.log(a === c);
console.log(String(a) === String(b));What does this print?
It prints: false
true
true
Arrays and objects are compared by reference: === checks whether both sides are the very same object, not whether they hold the same items. a and b are two separate arrays, while c is just another name for a. Comparing their string forms compares the contents.
=== on arrays and objects checks identity, not contents.