Basic things that you need to know about IF, ELSE Statement in JavaScript

JavaScript-if-else-statment.png

There are such situation in programming that a specific path needs to be chosen. IF ELSE is a life saver for that

[Flowchart Above]

IF statement:

it directly gives a condition and ONE path to follow in code.

Consider the example below. This shows if age of the person is greater than equal to then 18 ,return what's in the console.

carbon (3).png

IF...ELSE Statement:

It gives a condition and TWO PATHS to follow. One is if the condition is fulfilled, other is, when it is not

Consider example below. This shows in case of first condition that if age of the person is greater than equal to then 18 ,return what's in the first console. And if that is not the case, then return the second console

carbon (4).png

IF...ELSE IF Statement:

It is another loop that makes decision between various conditions

Consider for example below. We have several conditions and our code will execute one according to instructions. We mention the fruit as BANANA and then give several conditions to it (to execute according to input)

carbon (5).png

Thanks for reading Hashnode Community Let me know if you have nay other question(s) or suggestion(s) on twitter (at)AishTheCoder