JAVASCRIPT 
STATEMENTS 
Victor Perez
/ BLOCK STATEMENT
BLOCK ⁄ 
STATEMENTS 
● Delimited by a pair of curly brackets 
● Contains one or more statements 
● No block scope 
○ added in ES6 via let keyword
/ CONDITIONAL STATEMENTS
IF...⁄ 
STATEMENTS 
ELSE ● Executes a statement if the condition is true 
● Executes the optional second statement if the condition is false 
● Both if and else can only have 1 statement
NESTED ⁄ 
STATEMENTS 
IF...ELSE ● No elseif keyword
SWITCH ⁄ 
STATEMENTS 
● Compares the expression agans all case expressions using strict equal 
● Execution of the statements will start by the first matching case clause. 
● break statement forces the program to break out of the switch 
● default case expressions will always be executed
/ LOOP STATEMENTS
FOR ⁄ 
STATEMENTS 
● Executes a statement as long the condition is true 
● Variable declaration in the initialization are in the 
same scope as the for loop 
● An empty condition always evaluates to true 
● Only 1 statement
DO...⁄ 
STATEMENTS 
WHILE ● Executes a statement at least once and is re-executing it each 
time the condition evaluates to true 
● Only 1 statement
WHILE ⁄ 
STATEMENTS 
● Executes a statement as long as a specified condition evaluates to 
true 
● Only 1 statement
FOR...⁄ 
STATEMENTS 
IN ● Iterates over the enumerable properties of an object 
● On each iteration, a different property name is assigned to variable 
● Arbitrary order 
● Only 1 statement 
● Don’t use it for array’s!
LABEL ⁄ 
STATEMENTS 
● Label a statement 
● The labeled statement can be used with break or continue 
statements. 
● Label can be any valid JavaScript identifier 
● Avoid using labels!
BREAK ⁄ 
STATEMENTS 
● Terminates the current loop, switch, or label statement 
● Label is only optional if the break is used in a loop or switch, else its 
required
CONTINUE ⁄ 
STATEMENTS 
● Terminates execution of the statements in the current iteration of the 
current loop 
● Jumps to the final-expression of a for loop 
● Jumps to the condition of a while loop
/ EXCEPTION HANDLING STATEMENTS
THROW ⁄ 
STATEMENTS 
● Throws a user-defined exception 
● The statements after throw won't be executed 
● Will execute the first catch block in the call stack 
● Will terminate the program if there is not catch block in the full call 
stack
TRY...⁄ 
STATEMENTS 
CATCH ● Try block marks a block of statements to try 
● Catch clause specifies a response, should an exception be thrown 
● Finally clause executes after the try block and catch clause
/ FUNCTION STATEMENTS
FUNCTION ⁄ 
STATEMENTS 
● Declares function with the specified parameters 
● You can use the function before you declared it 
○ not by function expressions!
RETURN ⁄ 
STATEMENTS 
● Ends function execution 
● Specifies a value to be returned to the function caller 
● Default value is undefined
/ OTHER STATEMENTS
DEBUGGER ⁄ 
STATEMENTS 
● Invokes any available debugging functionality 
● This statement has no effect, if there is no debugger functionality available 
● Execution is paused at the debugger statement
WITH ⁄ 
STATEMENTS 
● Extends the scope chain for a statement 
● Not recommended 
● Forbidden in ECMAScript 5 strict mode.
EMPTY ⁄ 
STATEMENTS 
● Is used to provide no statement, where the syntax requires one
/ QUESTIONS?
THANKS 
@VICTORAPEREZ 
vpjs@victor-perez.nl

JavaScript statements

  • 2.
  • 3.
  • 4.
    BLOCK ⁄ STATEMENTS ● Delimited by a pair of curly brackets ● Contains one or more statements ● No block scope ○ added in ES6 via let keyword
  • 5.
  • 6.
    IF...⁄ STATEMENTS ELSE● Executes a statement if the condition is true ● Executes the optional second statement if the condition is false ● Both if and else can only have 1 statement
  • 7.
    NESTED ⁄ STATEMENTS IF...ELSE ● No elseif keyword
  • 8.
    SWITCH ⁄ STATEMENTS ● Compares the expression agans all case expressions using strict equal ● Execution of the statements will start by the first matching case clause. ● break statement forces the program to break out of the switch ● default case expressions will always be executed
  • 9.
  • 10.
    FOR ⁄ STATEMENTS ● Executes a statement as long the condition is true ● Variable declaration in the initialization are in the same scope as the for loop ● An empty condition always evaluates to true ● Only 1 statement
  • 11.
    DO...⁄ STATEMENTS WHILE● Executes a statement at least once and is re-executing it each time the condition evaluates to true ● Only 1 statement
  • 12.
    WHILE ⁄ STATEMENTS ● Executes a statement as long as a specified condition evaluates to true ● Only 1 statement
  • 13.
    FOR...⁄ STATEMENTS IN● Iterates over the enumerable properties of an object ● On each iteration, a different property name is assigned to variable ● Arbitrary order ● Only 1 statement ● Don’t use it for array’s!
  • 14.
    LABEL ⁄ STATEMENTS ● Label a statement ● The labeled statement can be used with break or continue statements. ● Label can be any valid JavaScript identifier ● Avoid using labels!
  • 15.
    BREAK ⁄ STATEMENTS ● Terminates the current loop, switch, or label statement ● Label is only optional if the break is used in a loop or switch, else its required
  • 16.
    CONTINUE ⁄ STATEMENTS ● Terminates execution of the statements in the current iteration of the current loop ● Jumps to the final-expression of a for loop ● Jumps to the condition of a while loop
  • 17.
  • 18.
    THROW ⁄ STATEMENTS ● Throws a user-defined exception ● The statements after throw won't be executed ● Will execute the first catch block in the call stack ● Will terminate the program if there is not catch block in the full call stack
  • 19.
    TRY...⁄ STATEMENTS CATCH● Try block marks a block of statements to try ● Catch clause specifies a response, should an exception be thrown ● Finally clause executes after the try block and catch clause
  • 20.
  • 21.
    FUNCTION ⁄ STATEMENTS ● Declares function with the specified parameters ● You can use the function before you declared it ○ not by function expressions!
  • 22.
    RETURN ⁄ STATEMENTS ● Ends function execution ● Specifies a value to be returned to the function caller ● Default value is undefined
  • 23.
  • 24.
    DEBUGGER ⁄ STATEMENTS ● Invokes any available debugging functionality ● This statement has no effect, if there is no debugger functionality available ● Execution is paused at the debugger statement
  • 25.
    WITH ⁄ STATEMENTS ● Extends the scope chain for a statement ● Not recommended ● Forbidden in ECMAScript 5 strict mode.
  • 26.
    EMPTY ⁄ STATEMENTS ● Is used to provide no statement, where the syntax requires one
  • 27.
  • 28.