What is the purpose of the block-level scope of javascript
Today, I would like to share with you the relevant knowledge of what the block-level scope of javascript does. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
The role of block-level scope: to resolve naming conflicts caused by too many global variables and functions. JavaScript turns a blind eye to repeated declarations, resulting in errors in the run results, and block-level scopes can solve this problem, allowing each developer to use his or her own variables without having to worry about messing up the global scope.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
What is a block-level scope?
The statement set in any pair of curly braces ({and}) belongs to a block, in which all variables defined are invisible outside the code block, which we call block-level scopes, such as for, while, if.
JavaScript does not have block-level scope (before the es6 standard came out, javascript did not have block-level scope), that is, a variable is defined in the code block of javascript, and the variable can still be used outside that code block, for example:
Vari= 1; if (iTunes 1) {var bread2;} alert (b); / / output 2 function outputNumbers (count) {for (vari=0;i)