Quick question about return or simmilar statements like console.log etc

Quick question about return or simmilar statements like console.log etc
0

#1

Im currently practicing some basics again just for fun, i havent had much chanse to code since i work seasonal job for 12 hours a day. So my question is, with code like this:

function myFunction(num1, num2) {
    
    if (num1 === num2) {
        return "cool";
    } else {
        return "false";
    }
    
    return "Fail";
}
myFunction(20, 10);

return “Fail” will only return Fail message when if statement doesnt make it which means not returning eighter “cool” or “false”. Am i correct?


#2

This function will never return “Fail”. If num1 is equal to num2, it will return “cool”. Those aren’t equal, it will return “false”.


#3

Well, with the code you have right now, the “Fail” return will never be reached.

As soon as you hit a return statement, you are exited out of the closest (loosely used) function.