JavaScript Syntax

Level 1: Fundamentals, Primitives, and Grammar.

RUNTIME TIME
10:00
NODE 1 OF 200% Answered
Question 1/20

> Which keyword is used to declare a variable that cannot be reassigned?

Curriculum & Technical ManualLevel: Beginner / Intermediate

Comprehensive Study Guide: JavaScript Core: Variables, Scope, Closures, Prototypes & Event Loop

JavaScript is the core programming language of the modern web, executing as a single-threaded, non-blocking, asynchronous runtime powered by an event loop.

To master JavaScript, developers must understand lexical scoping, execution contexts, hoisting, closure mechanics, truthy/falsy coercion, and prototype inheritance. These foundational pillars govern how data is stored, referenced, and executed across browser and server environments.

Core Technical Competencies Tested in This Lab

1
var vs let vs const & Hoisting

var is function-scoped and hoisted with an initial value of undefined. let and const are block-scoped and live in the Temporal Dead Zone (TDZ) until evaluated.

2
Closures & Lexical Scoping

A closure is a function's ability to retain access to variables from its parent lexical environment even after the parent function has finished executing.

3
The Event Loop & Concurrency

The call stack executes synchronous code. Asynchronous tasks are routed to Web APIs and queued into the Microtask Queue (Promises, queueMicrotask) and Macrotask Queue (setTimeout, setInterval).

4
Prototypes & Prototypal Inheritance

Every JavaScript object has an internal [[Prototype]] link (__proto__). Property lookups traverse this prototype chain until found or reaching null.

5
Strict Equality vs Type Coercion

Understanding implicit coercion rules (e.g. '5' + 2 vs '5' - 2) and why === is preferred over == in production.

6
Higher-Order Functions & Array Methods

Mastering immutable functional transformations with map, filter, reduce, find, some, and every.

Architectural Code Patterns & Implementation Standards

Data Encapsulation Using ClosuresStandard

Creating private state variables that cannot be accessed or modified from the global scope.

function createCounter(initialValue = 0) {
  let count = initialValue; // Private variable

  return {
    increment: () => ++count,
    decrement: () => --count,
    getValue: () => count
  };
}

const counter = createCounter(10);
counter.increment(); // 11
console.log(counter.getValue()); // 11
// count is completely inaccessible from the outside!
Key Insight: The returned methods form closures over the private 'count' variable, providing clean encapsulation without classes.

Production Best Practices

  • Default to 'const' for all variable declarations; only use 'let' when reassignment is explicitly required; never use 'var'.
  • Always use strict equality (===) to avoid subtle bugs caused by implicit type coercion.
  • Prefer pure functions and immutable array methods (map, filter, concat) over mutating methods (splice, push) to prevent side effects.
  • Handle Promise rejections using try/catch blocks with async/await rather than unhandled promise chains.

Common Pitfalls & Anti-Patterns

  • Accessing 'let' or 'const' variables before their declaration line, which throws a ReferenceError due to the Temporal Dead Zone (TDZ).
  • Accidental global variable creation by forgetting variable declaration keywords in non-strict mode.
  • Mutating objects passed by reference into functions, causing unpredictable bugs across unrelated modules.

Frequently Asked Conceptual Questions & Answers

Q1: What is the Temporal Dead Zone (TDZ)?

The TDZ is the period between entering a scope and the actual line where a 'let' or 'const' variable is declared. Although the variable is hoisted, it cannot be read or assigned until evaluation reaches the declaration statement. Attempting to access it earlier triggers a ReferenceError.

Q2: How does the Event Loop prioritize Microtasks over Macrotasks?

When the Call Stack empties, the Event Loop first flushes ALL pending microtasks (Promise callbacks, process.nextTick, MutationObserver) before executing the next single macrotask (setTimeout, setInterval, I/O). If microtasks continuously queue more microtasks, macrotasks are starved.

Ready to expand your skillset further?

Explore complete guided tutorials, interactive playgrounds, and comprehensive interview collections.

Explore Related Tools

Hand-picked utilities and calculators related to this tool.

Related Tools