在 JavaScript 中宣告和初始化變數之間的區別是什麼?
ECMAScript 規範中對變數的宣告和初始化進行了如下陳述 −
A var statement declares variables that are scoped to the running execution context’s VariableEnvironment. Var variables are created when their containing Lexical Environment is instantiated and are initialized to undefined when created. [...] A variable defined by a VariableDeclaration with an Initializer is assigned the value of its Initializer’s AssignmentExpression when the VariableDeclaration is executed, not when the variable is created.
以上定義了區別
- 所有變數都使用 undefined 值初始化。
- 在初始化詞法環境時對變數宣告使用 undefined 值進行初始化。
- 這個初始化不能當作一個賦值。
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP