Conditional statement
Conditional statement makes application behave different according to given condition.
if
1 | if(true){ |
The example above result appear “hello” at console.
Because there is “true” in the if statement.
It is always executed if there is “true” in the if statement.
1 | if(false){ |
The example above don’t executed, Because there is “false” in the if statement.
As you saw the example, “true” have meaning always executed and “false” have meaning always don’t executed.
else
“else” is used when you need process more complex case.
1 | var a = 1; |
The result is “hello” at console, because a’s value is 1.
1 | var a = 2; |
The result is “No hello” at console, because a’s value is 2.
else if
You can make more various case if use “else if”
1 | var a = 2; |
The example above result is No hello, Because true in the else if statement.