JavaScript Tutorial

The language for programming web pages.

JS Scope

JavaScript Scope

Scope determines the accessibility (visibility) of variables. JavaScript has three types of scope.

Scope Types:

  • Global Scope — Declared outside functions, accessible everywhere
  • Function Scope — Declared with var inside a function
  • Block Scope — Declared with let/const inside {}

Closure:

A closure is a function that remembers variables from its outer scope even after the outer function has returned.

Try It Yourself

Edit the code below and click Run to see the result live.

Source Code
Result
Topics