How does var declare scope in js
This article introduces the knowledge of "how to declare the scope of var in js". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Variables declared using the var operator in the global scope will become properties of the window object.
Var name = 'Stan'console.log (window.name) / / Stan
2. Variables defined using the var operator will become local variables that contain their functions. Omit the var operator when defining a variable in a function and create a global variable.
Function test () {var message = 'h2' / / Local variable} test () / / the local variable is destroyed after the function call console.log (message) / / error. This is the end of the introduction of "how var declares scope in js". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!