Skip to main content

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.




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.


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

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.


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.