Junior JavaScript

What is block scope?

Variables declared with let or const inside curly braces {} are accessible only within

that block.

Example:

if (true) {

let y = 20;

const z = 30;

// console.log(y, z); // ReferenceError

More from JavaScript Tutorial

All questions for this course