+ 1

Why not use if instead of else if ?

Why not use if instead of else if ?Ä° think they are same.But it should have smth makes them diffirent.

18th Jul 2018, 4:53 PM
Vuqar Samed
Vuqar Samed - avatar
3 Answers
+ 3
else if statement need less cpu than if statement. And in some case, youmay not want another if statement to be occured while an if statement is true, then you have to use the else if statement.
18th Jul 2018, 5:07 PM
LAWArthur
+ 2
No they are both different in javascript i am telling //with else if var age = 18; if(age<=18) alert("Teenager"); else if(age>18) alert("Adult"); else alert("some message"); Output is Teenager //with if if else var age = 18; if(age<=18) alert("Teenager"); if(age>18) alert("Adult"); else alert("some message"); Output is Teenager and some message And second thing is if you use two if both condition is true then it will owerwrite the data & if you use if and else if only one condition will execute either if or else if.I hope it is clear .
18th Jul 2018, 5:21 PM
áŽ‹á”˜âżá”ƒËĄ
áŽ‹á”˜âżá”ƒËĄ - avatar
+ 1
Thanks for detailed answer.
18th Jul 2018, 5:09 PM
Vuqar Samed
Vuqar Samed - avatar