在JavaScript中obj [name]和obj [' name']之间有什么区别?

时间:2017-02-04 20:26:11

标签: javascript oop object key

我有一个对象' Obj'有财产名称。

.container

但是对于以下情况输出是EmptyPropertyValue而不是NamePropertyValue。 为什么?

var Obj = {name: "NamePropertyValue", '': "EmptyPropertyValue", null: 'NullPropertyValue'}

console.log(Obj["name"]);  >>> Output is : NamePropertyValue

console.log(Obj["null"]);  >>> Output is : NullPropertyValue
console.log(Obj[null]);  >>> Output is : NullPropertyValue

什么是' name'在Javascript中?为什么默认情况下它具有空字符串值而不是' undefined'

console.log(Obj[name]);  >>> Output is : EmptyPropertyValue

1 个答案:

答案 0 :(得分:3)

  

在JavaScript中obj [name]和obj [' name']有什么区别

group_by是一个变量。 summarise是一个字符串。

方括号之间的值始终被评估为字符串。

name
  

什么是' name'在Javascript中?为什么默认情况下它具有空字符串值而不是'未定义'

这是name of the window

相关问题