+ 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.
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.
+ 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 .
+ 1
Thanks for detailed answer.