28

JavaScript statements

Embed Size (px)

DESCRIPTION

JavaScript presentation for 24/i, that will touch all JavaScript statements ( ES5 )

Citation preview

Page 1: JavaScript statements
Page 2: JavaScript statements

JAVASCRIPTSTATEMENTSVictor Perez

Page 3: JavaScript statements

/ BLOCK STATEMENT

Page 4: JavaScript statements

⁄ ⁄ ⁄

● Delimited by a pair of curly brackets

● Contains one or more statements

● No block scope

○ added in ES6 via let keyword

BLOCKSTATEMENTS

Page 5: JavaScript statements

/ CONDITIONAL STATEMENTS

Page 6: JavaScript statements

⁄ ⁄ ⁄

● 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

IF...ELSESTATEMENTS

Page 7: JavaScript statements

⁄ ⁄ ⁄

● No elseif keyword

NESTED IF...ELSESTATEMENTS

Page 8: JavaScript 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

SWITCHSTATEMENTS

Page 9: JavaScript statements

/ LOOP STATEMENTS

Page 10: JavaScript 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

FORSTATEMENTS

Page 11: JavaScript statements

⁄ ⁄ ⁄

● Executes a statement at least once and is re-executing it each

time the condition evaluates to true

● Only 1 statement

DO...WHILESTATEMENTS

Page 12: JavaScript statements

⁄ ⁄ ⁄

● Executes a statement as long as a specified condition evaluates to

true

● Only 1 statement

WHILESTATEMENTS

Page 13: JavaScript statements

⁄ ⁄ ⁄

● 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!

FOR...INSTATEMENTS

Page 14: JavaScript 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!

LABELSTATEMENTS

Page 15: JavaScript 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

BREAKSTATEMENTS

Page 16: JavaScript 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

CONTINUESTATEMENTS

Page 17: JavaScript statements

/ EXCEPTION HANDLING STATEMENTS

Page 18: JavaScript 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

THROWSTATEMENTS

Page 19: JavaScript statements

⁄ ⁄ ⁄

● 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

TRY...CATCHSTATEMENTS

Page 20: JavaScript statements

/ FUNCTION STATEMENTS

Page 21: JavaScript statements

⁄ ⁄ ⁄

● Declares function with the specified parameters

● You can use the function before you declared it

○ not by function expressions!

FUNCTIONSTATEMENTS

Page 22: JavaScript statements

⁄ ⁄ ⁄

● Ends function execution

● Specifies a value to be returned to the function caller

● Default value is undefined

RETURNSTATEMENTS

Page 23: JavaScript statements

/ OTHER STATEMENTS

Page 24: JavaScript 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

DEBUGGERSTATEMENTS

Page 25: JavaScript statements

⁄ ⁄ ⁄

● Extends the scope chain for a statement

● Not recommended

● Forbidden in ECMAScript 5 strict mode.

WITHSTATEMENTS

Page 26: JavaScript statements

⁄ ⁄ ⁄

● Is used to provide no statement, where the syntax requires one

EMPTYSTATEMENTS

Page 27: JavaScript statements

/ QUESTIONS?

Page 28: JavaScript statements

THANKS@[email protected]