Skip to content

Latest commit

 

History

History
52 lines (41 loc) · 1.39 KB

cl3mp3gi9043ky7nvbukk41f1.md

File metadata and controls

52 lines (41 loc) · 1.39 KB

If Statement In JavaScript With Examples

Hello everyone hope everyone is doing well. My name is Surya L, the purpose of this blog is to teach all about** If** Statement In JavaScript With Examples.

What is IF Statement:

If a condition is true, the if statement executes the block. The syntax of the if statement is as follows:

if( condition )
   statement;

An expression or a value can be used as the condition. The condition is usually evaluated to a Boolean value, which is true or false.

The if statement executes the statement if the condition is true. In any other case, the if statement passes control to the next statement after it.

Flowchart of IF Statement:

![if-block.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1653485690610/hrAKSPWRA.png align="left")

function proj(n)
{
    if(n>0)
    {
        console.log("Its Positive");
    }
}
proj(2)

The Output of above code is 👇 Its Positive

For example if the n value is -2

function proj(n)
{
    if(n>0)
    {
        console.log("Its Positive");
    }
}
proj(-2)

There will be no output

Conclusion:

  • If a condition is true, the if statement executes the block.
  • In any other case, the if statement passes control to the next statement after it.

Credits: I learned this topics in FreeCodeCamp which I explained in minified version

Thanks for reading the blog. Do let me know what you think about it.