E
E
eSelf2015-02-26 16:05:02
JavaScript
eSelf, 2015-02-26 16:05:02

Why does it output false when comparing two identical arrays?

For example:
var arr1 = [1,2,3];
var arr2 = [1,2,3];
console.log( arr1 == arr2 ); //Displays false I
just started learning js, I was interested in this moment.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DigitalSmile, 2015-02-26
@eSelf

You are comparing references to array objects, and they are different.
Compare for example:

var a = "123"; 
var b = "123"; 
console.log(a == b);
var c = new String("123"); 
var d = new String("123"); 
console.log(c == d);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question