JavaScript

JavaScript is the programming language of the web. It enables interactive user interfaces, asynchronous operations, server-side applications, desktop applications, and more.


Learning Path

Fundamentals

  • Variables (var, let, const)
  • Data Types
  • Type Coercion
  • Operators
  • Scope
  • Hoisting
  • Functions
  • Closures
  • Objects
  • Arrays

Intermediate

  • Event Loop
  • Call Stack
  • Execution Context
  • Prototype Chain
  • Classes
  • Modules
  • Error Handling
  • Promises
  • Async/Await

Advanced

  • Memory Management
  • Garbage Collection
  • Event Delegation
  • Design Patterns
  • Performance Optimization
  • Functional Programming
  • Web Workers

Example: Closures

A closure allows a function to access variables from its outer scope even after the outer function has returned.

function counter() {
  let count = 0;

  return function () {
    count++;
    return count;
  };
}

const increment = counter();

console.log(increment()); // 1
console.log(increment()); // 2
console.log(increment()); // 3

Why it Works

  1. counter() creates a local variable count.
  2. The returned function references count.
  3. JavaScript preserves that variable in memory.
  4. Each call updates the same variable.

Common Interview Question

What is the difference between let, const and var?
**var**

- Function scoped
- Can be redeclared
- Hoisted and initialized with `undefined`

**let**

- Block scoped
- Cannot be redeclared in same scope
- Exists in Temporal Dead Zone

**const**

- Block scoped
- Cannot be reassigned
- Must be initialized during declaration

Important Notes

Note

JavaScript is single-threaded but can perform asynchronous operations through the Event Loop.

Warning

Avoid using `var` in modern applications unless maintaining legacy code.

Tip

Master closures, promises, async/await, event loop, and prototype inheritance for senior-level interviews.

Event Loop Overview

Call Stack
    |
    v
Web APIs
    |
    v
Callback Queue
    |
    v
Event Loop
    |
    v
Call Stack

Frequently Asked Topics

Topic SDE-1 SDE-2
Scope
Closures
Event Loop
Prototypes ⚠️
Memory Management
Design Patterns

  1. Variables and Scope
  2. Functions
  3. Closures
  4. Objects
  5. Arrays
  6. Execution Context
  7. Event Loop
  8. Promises
  9. Async/Await
  10. Prototype Chain
  11. Memory Management
  12. Design Patterns

Next Steps

Continue with:

  • Fundamentals → Scope & Hoisting
  • Fundamentals → Functions
  • Fundamentals → Closures
  • Browser → Event Loop
  • Advanced → Memory Management