Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Full stack web developer
  • Location
    Delhi , India
  • Education
    BPIT, Bhagwan Parshuram Institute of Technology , BTech in Computer Science
  • Work
    Working Professional
  • Joined

More fromPUSHAN VERMA

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp