+ 4

what is the difference between else and if?

i have no idea

25th Jun 2017, 9:54 AM
The Black Eagle
The Black Eagle - avatar
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 ' }
25th Jun 2017, 10:20 AM
NSA94
NSA94 - avatar
+ 3
thank you!
26th Jun 2017, 7:48 AM
The Black Eagle
The Black Eagle - avatar
+ 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"); }
25th Jun 2017, 9:58 AM
Elie Douaihy
Elie Douaihy - avatar
+ 2
wow this really helped thanks so much ^^♄
2nd Jul 2017, 1:31 AM
The Black Eagle
The Black Eagle - avatar
+ 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 :)
25th Jun 2017, 10:20 AM
S.Naveen Kumar
S.Naveen Kumar - avatar
+ 1
Hii @kim Practice with more examples for better understanding...
26th Jun 2017, 8:16 AM
S.Naveen Kumar
S.Naveen Kumar - avatar
+ 1
if can use without else but else doesn't use without if
29th Jun 2017, 8:56 AM
Akansha Thakur
Akansha Thakur - avatar