Lesson 93 +15 XP

Statements and Keywords

Statements and Keywords

A quick reference of the statements and keywords you use the most.

Variable declarations

KeywordPurpose
letblock-scoped variable that can change
constblock-scoped constant
varolder, function-scoped variable

Control flow

KeywordPurpose
if, elsedecisions
switch, casemultiple choices
breakexit a loop or switch
continueskip to next loop iteration
returnexit a function with a value

Loops

KeywordPurpose
forcounted loop
whilecondition-first loop
doruns once before checking
for...ofloop over values
for...inloop over keys

Functions and classes

KeywordPurpose
functiondeclare a function
asyncmark a function as async
awaitwait for a promise
class, extends, superobject-oriented classes
newcreate an object from a class

Errors

KeywordPurpose
tryrun risky code
catchhandle errors
finallyalways run
throwcreate an error

TL;DR

  • let/const declare variables.
  • if/switch make decisions.
  • for/while loop.
  • try/catch handle errors.
  • class/extends build OOP.