JavaScript Fundamentals

My reference for JavaScript values, variables, operators, control flow, loops, and functions.

JavaScript Beginner–Intermediate

Variables & Data Types

Core JavaScript values and declarations used to store and work with data.

Core JavaScript values and declarations used to store and work with data.
Term / Syntax Name Description Example
let Block-Scoped Variable Declares a variable whose value can be reassigned. let count = 1;
const Block-Scoped Binding Declares a binding that cannot be reassigned. const siteName = "Web Dev Reference";
var Function-Scoped Variable Declares a variable scoped to its containing function rather than its block. var count = 1;
string Text Value Represents textual data. const name = "Jennifer";
number Numeric Value Represents numeric values, including integers and decimals. const score = 98.5;
bigint Large Integer Value Represents integer values of arbitrary size without losing integer precision. const largeNumber = 9007199254740993n;
boolean True/False Value Represents one of two logical states. const isVisible = true;
null Intentional Empty Value Represents the intentional absence of a value. const selectedItem = null;
undefined Missing Value Represents a value that has not been assigned or is otherwise missing. let result;
typeof Type Operator Returns a string describing a value's JavaScript type. typeof 42; // "number"
Array.isArray() Array Type Check Checks whether a value is an array. Array.isArray(items); // true
instanceof Instance Check Checks whether an object is an instance of a specified constructor or its inheritance chain. user instanceof User; // true
Number.isNaN() NaN Check Checks whether a value is the numeric value NaN without converting its type. Number.isNaN(result); // true
parseInt() Integer Parsing Parses a string and returns an integer. parseInt("42", 10); // 42
parseFloat() Decimal Parsing Parses a string and returns a number that can include a decimal. parseFloat("42.5"); // 42.5
Number() Number Conversion Converts a value to a number. Number("42"); // 42
String() String Conversion Converts a value to a string. String(42); // "42"
Boolean() Boolean Conversion Converts a value to a boolean based on its truthiness. Boolean(1); // true
truthy / falsy Boolean Context Describes how values are treated as true or false in a boolean context. Boolean(""); // false

Operators & Control Flow

Operators and statements used to calculate and assign values, compare conditions, make decisions, and repeat work.

Operators and statements used to calculate and assign values, compare conditions, make decisions, and repeat work.
Term / Syntax Name Description Example
+ - * / % ** Arithmetic Operators Performs addition, subtraction, multiplication, division, remainder, and exponentiation. total = price * quantity;
= Assignment Assigns a value to a variable. count = 2;
+= -= *= /= %= Compound Assignment Performs an arithmetic operation and assigns the result back to the variable. total += price;
++ -- Increment / Decrement Increases or decreases a numeric variable by one. count++;
=== Strict Equality Compares value and type without coercion. status === "ready"
!== Strict Inequality Returns true when value or type differs. count !== 0
< > <= >= Relational Comparison Compares whether one value is less than, greater than, or equal to another value. score >= 70
! Logical NOT Converts a value to a boolean and returns the opposite boolean value. !isLoggedIn
&& Logical AND Returns the first falsy operand, or the last operand if all are truthy. isLoggedIn && isAdmin
|| Logical OR Returns the first truthy operand, or the last operand if all are falsy. displayName || "Guest"
?? Nullish Coalescing Uses a fallback only when the left value is null or undefined. username ?? "Guest"
?: Conditional Operator Returns one of two expressions based on a condition. const label = isActive ? "Active" : "Inactive";
if / else Conditional Statement Runs different blocks based on a condition. if (score >= 70) { pass(); } else { retry(); }
switch Multi-Branch Conditional Matches one expression against multiple cases. switch (theme) { case "dark": applyDark(); break; }
break Exit Statement Exits the nearest loop or switch statement. if (item === target) { break; }
continue Skip Iteration Skips the rest of the current loop iteration and continues with the next one. if (!item.active) { continue; }
for Counted Loop Repeats a block while a condition remains true, with optional setup and update expressions. for (let i = 0; i < items.length; i++) { console.log(items[i]); }
while Conditional Loop Repeats a block while a condition remains true. while (count < 5) { count++; }
do...while Post-Test Loop Runs a block at least once, then repeats it while a condition remains true. do { count++; } while (count < 5);
for...in Object Property Loop Loops through the enumerable property names of an object. for (const key in user) { console.log(key); }
for...of Iterable Loop Loops through the values of an iterable such as an array, Map, or Set. for (const item of items) { console.log(item); }

Functions

Reusable blocks of behavior for organizing logic and transforming values.

Reusable blocks of behavior for organizing logic and transforming values.
Term / Syntax Name Description Example
function Function Declaration Creates a named reusable function. function greet(name) { return `Hi ${name}`; }
function expression Function Expression Creates a function as a value that can be assigned to a variable. const greet = function (name) { return `Hi ${name}`; };
=> Arrow Function Provides concise function syntax and inherits this from the surrounding scope. const double = value => value * 2;
return Return Value Ends a function and sends a value back to the caller. return total;
scope Variable Accessibility Determines where variables and functions can be accessed in the code. function greet() { const message = "Hi"; }
this Function Context References a value determined by how a regular function is called. const user = { name: "Jennifer", greet() { return this.name; } };
default parameter Fallback Argument Provides a fallback value when an argument is omitted or undefined. function greet(name = "Guest") { }
rest parameter Collect Arguments Collects remaining arguments into an array. function sum(...numbers) { }
callback Function Argument A function passed to another function so that function can call it. items.forEach(item => console.log(item));
recursion Self-Calling Function A function calling itself until a stopping condition is reached. function countdown(n) { if (n <= 0) return; countdown(n - 1); }