Last active
December 20, 2015 23:59
-
-
Save shuhei/6217126 to your computer and use it in GitHub Desktop.
In JavaScript, object keys are always strings.
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 obj = {}; | |
// null and 'null' | |
obj[null] = 1; | |
obj['null'] = 2; | |
console.log(obj[null]); // 2 | |
// Numbers | |
obj[3] = 3; | |
obj['3'] = 4; | |
console.log(obj[3]); // 4 | |
// Objects | |
function Foo() {} | |
function Bar() {} | |
var f = new Foo(); | |
var b = new Bar(); | |
console.log(f.toString()); // [object Object] | |
console.log(b.toString()); // [object Object] | |
obj[f] = 5; | |
obj[b] = 6; | |
console.log(obj[f]); // 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment