Using the variable “name” doesn't work with a JS object

后端 未结 4 1987
不知归路
不知归路 2020-11-21 06:11

The behaviour can be seen in this little snippet (execute it as a global script):

var name = {};
name.FirstName = \'Tom\';
alert(name.FirstName);
         


        
4条回答
  •  不思量自难忘°
    2020-11-21 06:47

    With ES6+, you could write your code as let name or const name. This won't assign it or try to override window.name. More on that here.

    let name = {};
    name.FirstName = 'Tom';
    alert(name.FirstName);

提交回复
热议问题