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
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Scope, Closures & the Execution C | JavaScript Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. JavaScript Course

Lesson 7 of 55

·javascript

Scope, Closures & the Execution Context

13 mins

Course progress13%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • A closure keeps references to the outer variables even after the outer function finishes.
  • Be careful with closures inside loops – use `let` or an IIFE to capture the current value.
  • `this` is *not* part of a closure; it is bound when a function is called.

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
Make it stickPractice what you've learned1 quiz · 7 practical tests · Optional activities from JavaScript CourseBrowse activities
Previous lessonFunctions – declarations, expressions & arrow functionsContinue to lesson 8The Document Object Model (DOM)Back to JavaScript Course curriculum