Baidu"s article says that the function declaration is in the first place, and that the variable is in the first place, who is in the first place? Ask for advice
Baidu"s article says that the function declaration is in the first place, and that the variable is in the first place, who is in the first place? Ask for advice
Brother, the function belongs to the first-class citizen in JS, and the function comes before
variable promotion occurs in the process of creating a variable object. The function declaration is scanned first, and then the variable declaration is scanned. If the variable name is the same as the function already declared, nothing will happen. The variable declaration will not interfere with the existing attribute of the same name
console.log(name);// name(){console.log('cc');}
console.log(age);// age(){console.log(18);}
var name = 'cc';
function age(){
console.log(18);
}
function name(){
console.log('cc');
}
you can take a look at this JavaScript Foundation Series-execution Environment and scope chain
guess that it is interpreted and executed according to the writing order. Practice test
first variable promotion only occurs when var is declared, and there are not so many problems with let and const.
in addition, who comes first and then does not affect what, not hard to say who comes first, then it is a function, why? Because it's the norm.
promote in order, and the variables defined by function are assigned values during the promotion phase, so the later definition overrides the values of the variables defined earlier. The variable defined by var will not be assigned during the promotion phase, but will only be promoted. If the variable is already defined by another var or funciton during the promotion phase, it will not have any impact, so there is no problem of overwriting the previously promoted value. The var statement is not really assigned until the execution time, so the value of the console.log is actually the result of the execution time.
console.log(foo)
function foo(){
console.log('bb')
}
function foo(){
console.log('cc')
}
var foo = 'aa'
console.log(foo)
use let to prove that it is indeed promoted sequentially
function test(){
function foo(){}
let foo;
}
test(); // let foo
function test2(){
let foo;
function foo(){}
}
test2(); // function foo()
if the function is promoted first, then test2 should report an error on the second line.
is compiled first and overwritten
so what is printed is not undefined
function declaration is promoted first
for example:
console.log(foo)
var foo = 'aa'
function foo(){
console.log('bb')
}
foo() {
console.log('bb')
}
var foo = 'aa'
Previous: Front and back end value transfer problem
Next: How to put the unicode code of iconfont in dom in the for loop of vue
what is the current level of support for vw,vh layouts in mobile browsers? ...
http: shrek.imdevsh.com demo. ask for help: the principle of inertia retardation effect in demo touchmove ...
I ve been looking for it for a long time, but I can t find it. 1. After the direct upload of web is completed, the server cannot know whether the file was uploaded successfully, who uploaded it, and the information of the file 2. Using web to dire...
for example, I request localhost:8080 a b c.cd proxy to http: www.aaaa.com api can you change a b c.cd to a b c , before proxy? means that the agent rewrites the original path before. ...
question 1. The project is a chat application, which needs to display the latest news in the chat window in real time. Using the scrollIntoView method id div for bottom, I want to put it at the bottom. As long as it can be displayed, other chat message...
var myNumber = { value: 1, add: function(i){ var helper = function(i){ console.log(this); this.value += i; } helper(i); } } myNumber.add(1); Why does this this point to window?? The add method called by the myNumber o...
Click the button to show that (Bing s daily wallpaper) is successful, and then when the background of the page changes, it takes time to render, and there will be a white background color. How to solve this? ...
1. Execute npm install-g pm2 2.pm2 pm2 start app.js pm2 3.ln -s root myapp pm2 usr local bin still failed to solve the problem messed up for a long time because no soft connection was created. ln -s root node-v8.9.0-linux-x64 lib node_...
want to use vue2.0 to develop a small web application for the company, running on the mobile side. How can the above functions be achieved? ...
vue.js implements specification selection on product details page Click to select version option and click to select color option. Highlight has been selected. How to display the selected version and color html Code < div class= "chose-ck " > : ...
ios embedded h5 page input box will not lose focus if you click on the blank space. The soft keyboard will not fold. what should I do? try to bind the click event to document. If the input box loses focus when you click, it is still invalid. ...
as shown in the figure, how to determine that the user clicked on this X, and execute the corresponding method. ...
var a = {0:"A",1:"B",2:"C",length:3}; var newa = Array.prototype.slice.call(a); console.log(newa); my understanding of this example is that the an object inherits and executes Array s slice method, but the slice method...
what s the difference between writing JavaScript code in a js file and writing code in < srcipt > < srcipt >? Why can I introduce other js files as require in the js file and do report an error in the < srcipt > tag . ...
Icon shows the red part. Choose how to write the effect in css ....
We are Mini Program s project. To get the code logged in by Wechat, request the backend api to get the sessionkey. But if it is a concurrent request, if it happens to expire at this time, and several requests go to get the sessionkey at the same time, t...
o ...
brief: because Mini Program s project uses wepy s framework, but you don t quite understand that the role of this interceptor is to integrate all the interfaces? Or? ...
win7 system, scaffolding vue-cli has been installed, there is a version, but the initialization project appears this hole, cannot verify this certificate? Please help ...
Mobile input focus cannot directly evoke the mobile phone keyboard, what is the related auxiliary operation? Simple H5 page, do not use any framework, how to automatically evoke the soft keyboard? ...