Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. JavaScript Course

Lesson 7 of 55 · javascript

Scope, Closures & the Execution Context

Duration: 13 mins

Two main scopes:

  • Global scope – accessible everywhere.
  • Function scope – created by each function.
  • Block scope – created by let/const.

A closure is a function that remembers the environment in which it was created.

Example: Simple closure

function makeCounter(){
  let count = 0;
  return function(){
    count += 1;
    return count;
  };
}
const counter = makeCounter();
console.log(counter()); // 1
console.log(counter()); // 2
Previous: Functions – declarations, expressions & arrow functionsNext: The Document Object Model (DOM)