75% developed

Common JavaScript Manual/Conditional statements

From Wikibooks, open books for an open world
Jump to navigation Jump to search

If statements[edit | edit source]

We can do so that some blocks of code should execute only if condition true. For it we should use "if" expression. Let's see example.

n = 6;
if(n > 0)print("n is positive");

Else statements[edit | edit source]

We also can make code block that should be executed only if condition false. For execute much commands just enclose it in '{' and '}'.

n = -5;
if(n > 0){
  print("n is positive");
}else{
  print("n is negative or zero");
}

Else if statements[edit | edit source]

Also we can set any number conditions and blocks of code for this conditions.

n = 0;
if(n > 0){
  print("n is positive");
}else if(n == 0){
  print("n is zero");
}else{
  print("n is negative");
}


Data types - Objects · While and For loops