DEV Community

ana
ana

Posted on

if_else in java script:

Image description

in this article i want explain some Tip about if and else.
in javaScript and also in another programming languages, the name of this topic is : Conditional Statements.
Im sure that you see this topic in your programming way in any language you work with it..
so you should know we use if and else word for our usage.
anyway, at first I write the syntax of if, else, etc.

if:

if (condition) {
  //  the things we want will be done if the conditions are True.
}
Enter fullscreen mode Exit fullscreen mode

else:

if (condition) {
  //  the things we want will be done if the conditions are True.
} else {
  //  the things we want will be done if the conditions are False.
}
Enter fullscreen mode Exit fullscreen mode

else if:

if (condition1) {
  //  the things we want will be done if the condition1 is True.
} else if (condition2) {
  //  the things we want will be done if the condition1 is False.
} else {
  //  the things we want will be done if the condition1 and condition2 is False.
}
Enter fullscreen mode Exit fullscreen mode

so it's done... these is all about if, else and else if.

at the end, i write a example and you write the answer in comment if you like;)

var x = 0;

if (x = 0){
console.log("I should keep going, it doesn't matter how hard is!");
}else if (x = 00){
console.log("trying it's my answer");
}else{
console.log("i should not have shame feeling about trying");
}
Enter fullscreen mode Exit fullscreen mode

enjoy,byeeeeè.

Top comments (0)