What is the correct fix?
const a = [1, 2];
const b = [1, 2];
if (a === b) {
console.log('same');
}
- Compare contents element by element
- Compare contents with a loose
== - Freeze both arrays before comparing
- Convert both with
Number(a)first
=== compares references for arrays, so two distinct arrays are never equal; compare contents.
Play Problem Solving ▸