Functions and conditional

I am starting wih conditional in Javascript, let’s say we have the following code, which is from one the challenges

function testLessThan(val) {
if (val<25) { // Change this line
return “Under 25”;
}

if (val<55) { // Change this line
return “Under 55”;
}

return “55 or Over”;
}

So if I evaluate

testLessThan(10);

shouldn’t return “Under 55” as well? Since it’s true. What I understand is that the first condition is satisfied, so the second condition is not checked, am I right?

But, in this case the function could be reduced to

function testLessThan(val) {
if (val<55) { // Change this line
return “Under 55”;
}

return “55 or Over”;
}

return ends function execution. If first condition is met function ends by returning ‘Under 25’, no further evaluations are done.

It depends, the function is specifically checking if a number is lower than 25, if you are not interested in that and you want only to check if a number is below or above 55 you can certainly reduce the function to this.

Yes, that’s what I thought, but I didn’t know about that return ends the execution, so in the first function I will modify it (if necessary) in order to get something like “It is between 25 and 55”.

Totally depends on what you want to check, these are examples to show you how these things work