注意:从ECMAScript版本3或5的角度提出了这个问题.在ECMAScript 6发布中引入新功能后,答案可能会过时.
varJavaScript中关键字的功能到底是什么,有什么区别
var someNumber = 2;
var someFunction = function() { doSomething; }
var someObject = { }
var someObject.someProperty = 5;
Run Code Online (Sandbox Code Playgroud)
和
someNumber = 2;
someFunction = function() { doSomething; }
someObject = { }
someObject.someProperty = 5;
Run Code Online (Sandbox Code Playgroud)
?
你什么时候使用其中任何一个,为什么/它做什么?
JavaScript声明和未声明变量之间的主要区别是什么,因为delete运算符不适用于声明的变量?
var y = 43; // declares a new variable
x = 42;
delete x; // returns true (x is a property of the global object and can be deleted)
delete y; // returns false (delete doesn't affect variable names)
Run Code Online (Sandbox Code Playgroud)
为什么会这样?全局声明的变量也是窗口对象的属性,为什么不能删除它?