"Unreachable 'break' after 'return'."; what does it mean?


I was doing the exercise for "I have to celebrate you baby", and while the code worked fine, I noticed these little triangle alert thingies, and when I moused over it said "Unreachable 'break' after 'return'." What does that mean?

I noticed a similar thing in a previous lesson, only there it was... I think it was "Unreachable 'return' after 'console.log'."... or was it the other way around? (EDIT: yeah, it was the other way around; "Unreachable 'console' after 'return'.")

In any case, I'm very curious about these "unreachable" messages :slight_smile:. I don't have any prior coding experience to speak of and I want to understand as much as I can!


return is same as break , in functionality. (note: return can return some data but break can not)
When execution sees return it halts the process (program execution) and takes execution out of function.

Same happens with break,when execution sees break in switch it acts same way.

So there no need of break as it(program execution) already halted by return statement.


Thanks for your answer! That really helps :smiley:.

I fidgeted around a bit, and apparently in the previous case I noticed, it was the "console" that was unreachable after the "return", not the other way around (I'll edit the original post to note that).

So that means if I want to return something, I have to do it at the end of the function then, because everything after it will be "unreachable"?


everything after it will be "unreachable"?

Yeah everything after return statement is unreachable and they(code after it) will never run.

function someFunction(someParameter) 
    //some code
    return something
   //more code

//more code will never able to get executed


Thanks so much for the explanation; I think I get it now! :grinning::+1:


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