Skip to main content

JavaScript if else

Same as the if statement and nothing more except another condition tethered with it called else. else is nothing but another condition where its body is invaded when the if body fails to meet the logic.

Syntax:

if(){

}else{

}

The syntax is similar to if with an extra else block below with it.

Example:


let salary = 50000;
if(salary <= 30000){
console.log('Salary Credited')
}else {
   
    console.log('Out of block')

}

Output: Out of block

This is the same example we used for if article. Here the salary logic does not satisfy the if block. So it goes below to else and executes that part alone.

Verdict:

The if..else paired up can be a great conditional statement for comparison purposes and other logical purpose too.

Tags
Submitted by arilio666 on October 1, 2021

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.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.