DEV Community

PUSHAN VERMA
PUSHAN VERMA

Posted on

if-else ,ternary Operator,switch statements in JavaScript

if-else

let age=16;

if(age===16)
{
console.log("your age is 16");
}
else if(age<16)
{
console.log("age is less than 16");
}
else if(age ==20)
{
console.log("you are no longer a teen ager");
}
else
{
console.log("age is more than 16");
}

Image description

Ternary Operator
console.log((age==16?"my age is 16":"my age is not 16"));

Image description

switch
switch(age)
{
case 16:
{
console.log("you are 16");
break;
}
case 18:
{
console.log("you are 18");
break;
}
case 20:
{
console.log("you are 20");
break;
}
default:
{
console.log("you are not 16,18,20 , bhad mei jao");
break;
}
}
Image description

Top comments (0)