Skip to content

Instantly share code, notes, and snippets.

@shuhei
Last active December 20, 2015 23:59
Show Gist options
  • Save shuhei/6217126 to your computer and use it in GitHub Desktop.
Save shuhei/6217126 to your computer and use it in GitHub Desktop.
In JavaScript, object keys are always strings.
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