var a; // Declare a variable with identifier a
function a() { // Declare a function, the identifier is also a
}
alert(typeof a);
displays "function", which is the priority of function Level higher than var.
Some people think this is the reason why the code is executed sequentially, that is, a is overwritten by the funcion executed later. Okay, swap them around.
function a() {
}
var a;
alert(typeof a);
The result still shows "function" instead of "undefined". That is, function declarations take precedence over variable declarations.
We slightly modify the code and assign a value when declaring a.
function a() {
}
var a = 1; // Note here
alert(typeof a);
At this time, "number" is displayed but not "function", which is equivalent to
function a() {
}
var a;
a = 1; // Note here
alert(typeof a);
means "var a = 1" is split into two steps. a has been reassigned, naturally it is the last value.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn