Conditional Statements in JavaScript
Conditional Statements in JavaScript are similar to the ones available in C language. We have below types of constructs.
- if
- if…else
- switch…case
Example on conditional statements
var a = 11
var b = 22
if (a%2==0){
console.log(“a is even”)
}else{
console.log(“a is odd”)
}
Example on switch statement
var a = 11
switch (a%2)
{
case 1: console.log(“a is odd”);break;
case 0: console.log(“a is even”);break;
}
a = 12.1
console.log(“value of a ” + a);
Recent Comments