JavaScript: if statement

One of the conditional statements 'if' is a type of condition which has a block body and allows certain conditions which are satisfied logically or comparatively within its body block.

Syntax:

if(){


}

The 'if' must be in lower case only, and logic will go inside the brackets.

Example: Negative Scenario

let salary = 50000;

if(salary <= 20000){
console.log('Salary Credited')
}

console.log('Out of block')

Output: Out of block

Here, as the condition given inside the if has failed it didn't go inside the condition block and execute the print statement. So, it came outside the block and printed the other print statement.

Example: Positive Scenario

let salary = 50000;

if(salary >= 50000){
    console.log('Salary Credited')
}

Output: Salary Credited

As the condition now is satisfied it went inside the block did what it had to do.

Verdict:

So, this pretty much is if statement, there are more to this that we will discuss in other articles.

Fri, 10/01/2021 - 12:28

Authored by

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.
Tags