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 trialKyle Pate
2,710 PointsWhy do we use {}? As in: res.render('hello', {name: req.body.username)}) Why is req.body.username in brackets?
I'm curious what this syntax means.
app.post('/hello', (req, res) => { res.render('hello', {name: req.body.username}); });
Why is req.body.username in {}?
2 Answers
Jesus Mendoza
23,289 PointsHi Kyle,
You wrap it in curly brackets because it has to be an object where the property name is name
and the value is the value of req.body.username
.
Cheers!
Michael Kristensen
Full Stack JavaScript Techdegree Graduate 26,251 PointsThe entire assignment of name
to the value of req.body.username
is in the brackets, because it is an 'injected code segment', or a function that is executed at that stage. In essence, you are simply asking the program to do this task, when you reach that segment of the code;
'Render hello.pug, and also assign name
to the value of req.body.username
immediately' is in essence the command you are giving.