if-else Statement of JavaScript

Card image cap

if-else Statements Definition:

The if...else statement is a form of control statement that allows JavaScript to execute statements in more controlled way.

If the condition evaluates to true then one block of statements will mget executed and if the condition is false other block of the statements will get executed.

It is also used to specify a block of code to be executed, if the same condition is false.

Syntax:

Flow Chart:


Example:

Result:

Click button to display a time-as per greeting:



Read Also


Card image cap