HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

JavaScript Statements

In JavaScript, statements are individual instructions that are executed sequentially to perform specific actions or operations. Here's an overview of some common types of JavaScript statements:

Example

        let a, b, c;    // Statement 1
        a = 4;          // Statement 2
        b = 5;          // Statement 3
        c = a + b;      // Statement 4

Variable Declaration:

Example

  var x; // Declaration
    var y = 5; // Declaration with initialization

Assignment:

Example

x = 10; // Assignment

Conditional Statements: if...else Statement:

Example

  if (condition) {
    // code to be executed if condition is true
} else {
    // code to be executed if condition is false
}

switch Statement:

Example

 switch (expression) {
    case value1:
        // code to be executed if expression === value1
        break;
    case value2:
        // code to be executed if expression === value2
        break;
    default:
        // code to be executed if expression doesn't match any case
}

Loops:for Loop:

Example

 for (initialization; condition; increment/decrement) {
    // code to be executed repeatedly
}

while Loop:

Example

while (condition) {
    // code to be executed as long as condition is true
}

do...while Loop:

Example

 do {
    // code to be executed at least once, then repeatedly if condition is true
} while (condition);

Function Declaration:

Example

function functionName(parameter1, parameter2) {
    // code to be executed
}

Return Statement::

Example

 return value; // Exits the function and returns a value

Break and Continue:

Throw Statement:

Example

 throw 'Error message'; // Throws an error

Try...Catch Statement::

Example

 try {
    // code that might throw an error
} catch (error) {
    // code to handle the error
}