Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSurya Dutt
Courses Plus Student 2,875 Pointscode after return statement
How the code block after return statement is working in this functions topic .I heard that return is the last statement of the program and anything after it will be neglected?
1 Answer
Felipe Laso-Marsetti
3,158 PointsYou are correct. Any code that you put after a return statement is not going to give you any errors as long as it's correct, but it will not run at any point.
It is basically code that is unreachable.
In certain cases you need to return from a function but still do something afterwards, for these scenarios there are concurrency mechanisms you can use, timers, and some other elements that allow you to do this.
But, as stated before, the return statement is the last thing that gets executed in a function and everything after it is ignored :)