The difference between If and Else if

Hi there,

I am taking the JavaScript course and struggle to understand the below code.
From what I’ve learned, if we use several if statements in a code, all of them should be subsequently executed.

The output of the below function is “Under 25”, but I struggle to understand why it is not “Under 55”. Even if the first condition evaluates to true, so does the second one and if they are executed in an order then “Under 25” should be overwritten by the second condition and return “Under 55”. Why does the code just stop running when the first condition is true? What am I missing here? Now I really don’t get the difference between if and else if.

Thank you for your help!

A return statement immediately stops your function. No further lines of code are run inside of your function after you hit a return.

1 Like

Ahh didn’t think of that. Thank you!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.