$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #65

What is the correct fix?

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