JavaScript Statements

JavaScript Statements

JavaScript Statements
In JavaScript statements are instructions to be executed by web browser (JavaScript core)
  • Any language has set of vocabulary
  • These special purpose keywords are used to construct statements as per language syntax and cannot be used as JavaScript variables, functions, methods or object names.
  • The limited set of keywords help us to write unlimited statements.
The Syntax of JavaScript Statements is as follows:
JavaScript Compound Statement
Control Statement in JavaScript(if , if..else, Nested if, if-else-if )
Control Statement is also  called Decision-making. Decision-making is about deciding the order of execution of statements based on certain conditions or repeating groups of statements until certain specified conditions a met.
C++ handles decision making by supporting the following statements are as follows:
Control Structures in Java — Conditional statements | by Nickson Joram |  Javarevisited | Medium
Conditional Statement
  • if statement
The if statement used to specify a block of code to be executed, if the same condition is false.
The Syntax of else statement is as follows:
if (condition) {
  // if condition is true then block of code to be executed
} else{
  // if condition is false then block of code to be executed
  • if else statement
C++ if-else statement used to specify a new condition if the first condition is false.
The Syntax of else-if statement is as follows:
if (condition1) {
  // if condition1 is true then block of code to be executed now.
else if (condition2) {
  // if condition1 is false then block of code to be executed now.

else {
  // if condition1 and condition2 is false then block of code to be executed now.
  • Switch Statement
The switch statement used to specify many alternative blocks of code to be executed. In other words, The Switch statement is used to perform different actions based on different conditions like on or off.
The Syntax of Switch statement is as follows:
switch (expression)
    case condition1: // code to be executed if expression = condition 1;
    case condition2: // code to be executed if expression = condition 2;
    default: // code to be executed if expression doesn't match any cases
How does the switch statement work?
The expression is evaluated once and compared with the values of each case condition.
If there is a match, the corresponding code after the matching condition is executed. For example, if the value of the variable is equal to expression = 1, the code after expression = 2: is executed until the break statement is encountered.
If there is no match, the code after default: is executed.
Jump Statement
Jumping statement unconditionally transfer program control within a function. C++ language provides us multiple statements through which we can transfer the control anywhere in the program.
There are jump statement is as follows:
  1. Break 
  2. Continue
  • Break Statement
In Computer Programming, The break statement terminates loop immediately when it is encountered, Simply comes out of the loop. Immediate after the closing brace of loop will be executed. 
The Syntax of the Break statement is as follows:
  • Continue Statement 
The continue statement skips some statements inside the loop. Loop will be restarted when continue is encountered.
The Syntax of the continue statement is as follows: