Beace Lee

Beace Blog

Written by Beace Lee who lives and works in China building useful things. You should follow him on Twitter

JavaScript一些有趣的地方

March 18, 2017

对象(Object)

  • 对象不加引号和加引号的区别
var a = {a: "a"};
var b = {"b": "b"};
console.log(a); //"a"
console.log(b); //"b"
  • 特殊情况不可以用的属性访问
var a = {0: "a"};
console.log(a.0); //Uncaught SyntaxError: Unexpected number
//竟然可以像一个数组进行访问
console.log(a[0]); // "a"
//为了以便区分,可以加上引号
console.log(a['0']) // "a"