Given the Express route below and an EJS template that displays <%= message %>, what will the user see in the browser?
app.get('/greet', (req, res) => { res.render('greet', { message: 'Hello, friend!' }); });
Remember that res.render passes data to the template, and EJS replaces <%= %> with the value.
The message variable is passed to the EJS template. The template uses <%= message %> which outputs the string 'Hello, friend!'. So the user sees that text.
Choose the correct way to pass title and user variables to a Pug template in Express.
app.get('/profile', (req, res) => { // pass variables here });
Remember that res.render takes the template name and a single object with all variables.
Option B correctly passes an object with both title and user properties. Other options use invalid syntax or multiple objects which is not allowed.
Examine the code below. The template does not receive the name variable. What is the cause?
app.get('/hello', (req, res) => { const name = 'Alice'; res.render('hello'); });
Check how variables are passed to templates in Express.
The variable name is declared but never sent to the template. You must include it in the object passed to res.render.
Given this Express route and a Pug template that uses user.name and user.age, what will be rendered?
app.get('/user', (req, res) => { res.render('user', { user: { name: 'Bob', age: 30 } }); });
Remember how nested objects are accessed in templates.
The user object with name and age is passed correctly. The template accesses these properties and displays their values.
Why should the data passed to Express templates be plain JavaScript objects rather than complex types like functions or class instances?
Think about how templates access and display data.
Templates expect plain objects with properties they can read and display. Complex types like functions or class instances may not serialize or render properly, causing errors or confusing output.