+ 4
what is the difference between else and if?
i have no idea
7 Answers
+ 4
when you need to do something only some condition(s) are true ->
if(some condition){
' if condition is true do this things '
}
else{
' otherwise run this things '
}
+ 3
thank you!
+ 2
a=2
b=4
if(a>b){
alert("a greater than b");
{
else { //if not,or anything else (a<b)
alert("b greater than a");
}
+ 2
wow this really helped thanks so much ^^â„
+ 1
str1 = 100
str2 = 50
if(str1 == str2) //if this condition is true the following lines of code will be
{ //executed
alert("Same")
}
else //If the condition in if fails then else statement executes
{
alert("Not Same")
}
Output: Not Same
str1 = 100
str2 = 100
if(str1 == str2) //This condition is true now
{
alert("Same")
}
else
{
alert("Not Same")
}
Output:Same
This is if and else statements :)
+ 1
Hii @kim Practice with more examples for better understanding...
+ 1
if can use without else but else doesn't use without if