what is block scope in javascript

what is block scope in javascript

1 year ago 68
Nature

Block scope in JavaScript refers to the accessibility of variables within a block of code, which is delimited by curly braces {} . Prior to ES6, JavaScript only had global scope and function scope. However, ES6 introduced two new keywords, let and const, which provide block scope in JavaScript. Variables declared with let and const inside a block cannot be accessed from outside the block. On the other hand, variables declared with the var keyword do not have block scope and can be accessed from outside the block.

In summary, block scope in JavaScript refers to the accessibility of variables within a block of code delimited by curly braces {}. Variables declared with let and const inside a block cannot be accessed from outside the block, while variables declared with var can be accessed from outside the block.

Read Entire Article