Created
December 10, 2012 08:49
-
-
Save roine/4249395 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//compare two distinct array | |
// check for length and value at each index | |
function equalArrays(a,b) { | |
if (a.length != b.length) return false; | |
for(var i = 0; i < a.length; i++) | |
if (a[i] !== b[i]) return false; | |
return true; | |
} | |
var a = ['hello', 'world'], | |
b = ['hello', 'world']; | |
a === b; | |
/* return false */ | |
equalArrays(a, b); | |
/* return true */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = [1]; | |
var b = a; | |
a == b; | |
a === b; | |
/* return true because they refere to the same value */ | |
a[0] = 2; | |
a[0]; /* 2 */ | |
b[0]; /* 2 */ | |
/* here it's obvious that a and b share the same reference */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment