Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

317
Views
how is [1,2,3]==[1,2,3] false in javascript?

how is [1,2,3]==[1,2,3] and [1,2,3]===[1,2,3] false? Would appreciate a simple explanation. Came across this while watching a youtube video.. anymore "anomalies" like this?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

The == operator checks whether the two operands reference the same object. While the two objects (arrays are objects) may have the same content, they are different instances, and thus the expression is false.

about 4 years ago · Juan Pablo Isaza Report

0

The === and == operators compares arrays by reference (i.e. location in memory), the easy way to think about it is that "they are different arrays with the same values".

If you give you arrays a name, maybe the reason for this will be clearer:

const arr1 = [1, 2, 3];
const arr2 = [1, 2, 3];

console.log(arr1 === arr2);

And arr1 is not the same array as arr2.

Conversely, this will log true, because it compares the same reference:

const arr = [1, 2, 3];

console.log(arr === arr);
about 4 years ago · Juan Pablo Isaza Report

0

They are not equal because they are not the "same". In js, if you do [1,2,3] it stores the array as a variable with no name. Give it a name, say 'r', and do r==r and it will return true because window.r is the same as window.r. But window.undefinedvariable0 is not the same as window.undefinedvariable1, although they are visually the same.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!