In JavaScript, variables have either global scope or function scope, but not block scope. This means that variables declared within a function are local to that function and not accessible outside of it. This concept is known as “function-level scope.”
However, starting from ECMAScript 6 (ES6), JavaScript introduced the let
and const
keywords, which allow variables to be declared with block scope. Variables declared with let
and const
are scoped to the nearest enclosing block, which can be a block statement, a loop, or a conditional statement. This concept is called “block-level scope.”
So, to answer your question, JavaScript traditionally doesn’t have block-level scope, but with the introduction of let
and const
, it does support block-level scope in addition to function-level scope.