Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

JavaScript

Complete JavaScript Fundamentals Mastery


Topics

# Topic Key Points
1 Data Type Primitive (stack) vs Reference (heap)
2 Variable var, let, const, hoisting, TDZ
3 Type Coercion Implicit vs Explicit conversion
4 Template Literal Backticks, interpolation, multi-line
5 Truthy & Falsy 8 falsy values, everything else truthy
6 Destructuring Array [], Object {}, rest, default, rename
7 Parameters vs Arguments Rest ..., default params, arguments object
8 Optional Chaining ?. safe access, returns undefined not error
9 Equality & Comparison == (coercion) vs === (strict)
10 Strict Mode ES5, safer code, no duplicates, restricted keywords
11 Nullish Coalescing ?? operator
12 Ternary Operator condition ? a : b
13 Shadowing Inner scope variable hides outer
14 Short-circuit Evaluation && and || early exit
15 Loop & Iteration for, for...in, for...of, while, do...while
16 typeof vs instanceof Type checking approaches

Data Type

  • Primitive Data Type (Immutable) — stored in stack
    • Number
    • String
    • Boolean
    • undefined
    • null
    • BigInt
    • Symbol
  • Reference Data Type (Mutable) — stored in heap
    • Object, Array, Function, Date, Map etc.
    • Variable holds reference, not actual value
    • Reference comparison returns false (different addresses)
    • const prevents reassigning the reference, not mutating the value

Variable

  • var — redeclaration & reassignment allowed, hoisted with value undefined
  • let — no redeclaration, reassignment allowed, hoisted but in TDZ
  • const — no redeclaration, no reassignment, hoisted but in TDZ

Type Coercion

  • Implicit — JS auto-converts types
    • + operator special behavior (string concatenation)
    • - * / convert to number
  • Explicit — developer converts manually
    • Number(), String(), Boolean(), parseInt()
    • Object to Primitive conversion

Template Literal

  • Uses backticks ` for strings
  • Multi-line string support
  • String interpolation: `${variable}`

Truthy & Falsy Values

  • Falsy: false, 0, -0, 0n, "", null, undefined, NaN
  • Everything else is truthy (including "0", "false", [], {})

Destructuring

ES6 feature that allows extracting values from arrays or properties from objects and assigning them into variables in a concise way.

  • Array Destructuring

    • [] syntax
    • ... rest operator — collects remaining elements
    • = default value
    • , skip element
  • Object Destructuring

    • Works based on property name, not position
    • {} syntax
    • Rename while destructuring: const { name: userName } = user
    • Default value support
    • Dot notation for access
    • Bracket notation when key has special characters: user["my-age"]

Parameters vs Arguments

  • Parameters — variables defined in the function
    • Rest parameter (...) — takes all arguments into a single array
    • Default parameter — allows giving a default value to parameters
  • Arguments — actual values passed when calling the function

Optional Chaining

Safely access properties — widely used with API responses. Returns undefined instead of throwing an error if a property is not found.

user?.name             // property
user?.address?.city    // nested property
user?.sayHello?.()     // method
users?.[0]             // array/dynamic property

Equality & Comparison

  • == (loose equality) — compares value, may perform type coercion if types differ
  • === (strict equality) — compares both value and type, no type coercion

Strict Mode

Introduced in ES5. Makes code safer:

  • Prevents deleting non-configurable properties
  • Disallows duplicate parameter names in functions
  • Reserved words become restricted

Nullish Coalescing

?? — provides a default/fallback value when the left-hand side is null or undefined. Unlike ||, it does NOT fall back on other falsy values (0, "", false, NaN).

const username = null;
const result = username ?? "Guest";
console.log(result); // Guest — only null/undefined trigger the fallback

const count = 0;
console.log(count ?? 10); // 0  (?? keeps it, since 0 isn't null/undefined)
console.log(count || 10); // 10 (|| falls back, since 0 is falsy)
  • ?? — checks only null/undefined
  • || — checks any falsy value (0, "", false, null, undefined, NaN)

Ternary Operator

Shorthand for if...else. Since it takes 3 operands, it's known as the ternary operator.

condition ? valueIfTrue : valueIfFalse

Can be chained for multiple conditions:

marks >= 90 ? "A" : marks >= 40 ? "B" : "C"

Shadowing

Occurs when a variable declared in an inner scope has the same name as one in an outer scope. The inner scope variable takes precedence and hides (shadows) the outer one within that scope.

let x = 10;
{
  let x = 30; // shadows outer x
  console.log(x); // 30
}

Related concepts:

  • Hoisting — variable/function declarations are processed before code execution, during the memory allocation phase
  • Scope Chain — the chain of scopes JavaScript searches through when looking up a variable

Short-circuit Evaluation

JavaScript stops evaluating an expression as soon as the final result is already determined — it doesn't always evaluate the entire expression.

  • && — if the left side is falsy, the right side is not evaluated
  • || — if the left side is truthy, the right side is not evaluated
  • ??= (nullish coalescing) — the right side is evaluated only if the left side is null/undefined

Loop & Iteration

  • For Loop — most commonly used looping mechanism, iterates using (initialization; condition; increment/decrement)
    • Flow: initialize → condition → code → increment/decrement → condition → code → ...
  • Iterable — a value/object whose elements can be accessed one by one; implements the Symbol.iterator method
  • For Of Loop — used to iterate over the values of an iterable
  • For In Loop — used to iterate over an object/array and get the keys
  • While Loop
  • Do While Loop

typeof vs instanceof

  • typeof — identifies the type of a value
    typeof "Ashu"       // "string"
    typeof 25           // "number"
    typeof true         // "boolean"
    typeof undefined    // "undefined"
    typeof {}           // "object"
    typeof []           // "object"
    typeof function(){} // "function"
  • instanceof — checks whether an object is an instance of a particular constructor/class; also used to check the prototype chain relationship

About

Complete JavaScript fundamentals guide covering core concepts from data types to loops — built as a quick-reference for interview prep and mastering JS basics.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors