javascript
Scope in JavascriptjavascriptLevel1
Progress0%
Contents
Scope in Javascript
1 / 12
Introduction
Scope — Global, Local, Block
Scope determines where in the code a variable is accessible. If a variable is "in scope", you can read and write it. If it is "out of scope", accessing it throws a ReferenceError.
codejs
1function greet() {
2 let message = "Hello"; // only accessible inside greet
3}
4
5console.log(message); // ReferenceError: message is not definedJavaScript has three types of scope: global, local (function), and block.