javascript
javascript
Scope in Javascript
Live
bolt
Level1
Progress0%

Scope in Javascript

CARD 1

Introduction

Login to report note issues for this section.

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 defined

JavaScript has three types of scope: global, local (function), and block.