Statements and Keywords
A quick reference of the statements and keywords you use the most.
Variable declarations
| Keyword | Purpose |
|---|
let | block-scoped variable that can change |
const | block-scoped constant |
var | older, function-scoped variable |
Control flow
| Keyword | Purpose |
|---|
if, else | decisions |
switch, case | multiple choices |
break | exit a loop or switch |
continue | skip to next loop iteration |
return | exit a function with a value |
Loops
| Keyword | Purpose |
|---|
for | counted loop |
while | condition-first loop |
do | runs once before checking |
for...of | loop over values |
for...in | loop over keys |
Functions and classes
| Keyword | Purpose |
|---|
function | declare a function |
async | mark a function as async |
await | wait for a promise |
class, extends, super | object-oriented classes |
new | create an object from a class |
Errors
| Keyword | Purpose |
|---|
try | run risky code |
catch | handle errors |
finally | always run |
throw | create an error |
TL;DR
- let/const declare variables.
- if/switch make decisions.
- for/while loop.
- try/catch handle errors.
- class/extends build OOP.