But functions are by no means the only unit of scope. Block-scope refers to the idea that variables and functions can belong to an arbitrary block (generally, any pair) of code, rather than only to the enclosing function.
In ES6, the keyword (a cousin to the var
keyword) is introduced to allow declarations of variables in any arbitrary block of code. if (..) { let a = 2; }
will declare a variable that essentially hijacks the scope of the if
‘s { .. }
block and attaches itself there.
[^note-leastprivilege]: