The ET and const declarations within {} will become externally inaccessible values, but Const declares constants and cannot modify
The function is the most common scope unit in JavaScript. In essence, a variable or function declared inside a function will
In the scope of the "hidden" up, this is intentional good software design principles.
But the function is not the only scope unit. Block scopes refer to variables and functions that not only belong to the scope,
It can also belong to a block of code (usually referred to as {:} internal).
Starting with ES3, the Try/catch structure has a block scope in the catch clause.
The Let keyword (a cousin of the Var keyword) was introduced in ES6 to declare variables in any block of code. If
(..) {Let A = 2;} Will declare a variable with the IF {.} block, and add the variable to the block
In
Some people think that block scopes should not be used entirely as an alternative to function scopes. Both functions should be present at the same time, open
The sender can and should also choose which scopes to use as needed to create good code that is readable and maintainable.
function scope and block-level scope--JavaScript you don't know