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 trialBegana Choi
Courses Plus Student 13,126 Pointswhy next(err); not close the code the end and move forward?
in the video, Joel said that
app.use( ( req,res,next ) => {
const num = parseFloat(req.body.number);
if( isNaN(num)){
const err = new Error('Submitted value is not a number');
** here is where I'm talking about
next(err);
}
const sum = num * 2;
req.doubled = sum;
next();
});
it doesn't close out the middleware function. but why? can somebody explain to me why it occurs another error?
1 Answer
Steven Parker
231,269 PointsThe only way to end a function early is with a "return" statement (or a "throw"). The instructor adds "return" to fix the issue just a few moments later in the same video.