Home >Web Front-end >JS Tutorial >In-depth analysis of the difference between Javascript global variables var and non-var_Basic knowledge
I believe you are familiar with global variables. A variable defined in the form of a=1 in the function scope will be a global variable. In the global scope, the following three forms can be used to create a variable that is globally visible. Naming:
There are two differences between var and non-var:
1 The global variable of var cannot be deleted, because delete intelligently deletes the deletable attributes of the object, and the global attributes defined by var will be marked as non-deletable. It should be noted that if delete is unsuccessful, an error will not be thrown. The return value of delete is true|false.
2 Global variables defined by var will be promoted, but global variables defined without var will not be promoted. You can see the execution results of the following program: