Explore 100's Of Free Video Tutorials

Keep Learning, Keep Coding & Keep Sharing

Conditional Statements - Part 1

Notes:

JavaScript Conditional Statements:

Conditional / selection statements:
execute code based on the result of a given conditional expression

if,
if else,
else if ladder,
switch case

if statement:
syntax:
if(conditional expression)
{
statements; // true part
}
Browser executes true part; if the conditional expression inside the parenthesis evaluates to true.

if else statement:
syntax:
if(conditional expression)
{
statements; // true part
}
else
{
statements; // false part
}

Browser executes true part; if the conditional expression inside the parenthesis evaluates to true, else it executes the false part.

Note: if the true part gets executed then the false part will not get execute, vice versa.

Example code:
var a = 20;
if(a == 10)
{
document.write("a is equal to 10");
}
else
{
document.write("a is not equal to 10”);
}

Interview Questions: