JavaScript Statements
Overview
About this index
Statements are the instructions that control flow: conditions, loops, declarations, and jumps like return or throw. Open a topic below for a short beginner guide with examples.
Index
Topics
| Topic | Summary |
|---|---|
if...else | run code when a condition is true, use else and else if branches, with clear beginner examples |
switch | match a value against cases, use break, and handle a default branch with beginner examples |
for | init, condition, step, loop a known number of times, and avoid off-by-one mistakes |
while | repeat while a condition is true, avoid infinite loops, with beginner examples |
do...while | run the body at least once, then repeat while the condition stays true |
for...in | loop enumerable property keys of an object, and why arrays usually prefer for...of |
for...of | loop iterable values from arrays, strings, Maps, and Sets with clear beginner examples |
let / const / var | block scope vs function scope, redeclaration rules, and when to choose const |
return | send a value out of a function, stop the function early, and what happens with no value |
break / continue | exit a loop early or skip one iteration, with switch break notes |
for await...of | loop over async iterables and async generators. |
function | declare a named function with parameters and return. |
function* | declare a generator that yields values. |
async function | declare a function that returns a Promise. |
async function* | declare an async generator for for await...of. |
throw | raise an error on purpose, throw Error objects, and catch them with try...catch |
try...catch | catch thrown errors and run finally cleanup (lives under Language Concepts). |
using | dispose resources with Symbol.dispose. |
await using | async dispose with Symbol.asyncDispose. |
debugger | pause when DevTools is attached. |
label | name a loop for break/continue. |
with | legacy scope extension (avoid). |
Frequently Asked Questions
A complete instruction such as if, for, or return. Expressions produce values; statements do work.
Start with if...else and for, then let/const/var, then for...of.
CODETOFUN NEWS
Stay Ahead in Tech
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful
