What is the main purpose of passing data to templates in Express?
Passing data to templates allows you to send dynamic content from your server to the HTML views, so the page can show different information based on the data.
Click to reveal answer
beginner
How do you pass data to a template using Express's res.render() method?
You pass an object as the second argument to res.render(), where keys are variable names in the template and values are the data you want to show.
The data must be passed as an object with keys matching template variables.
Step 2: Check data types for variables
name is a string and tasks is an array, both correctly passed in res.render('dashboard', { name: 'Eve', tasks: ['Buy milk', 'Call Bob'] });.
Step 3: Evaluate other options
The other options use incorrect syntax such as multiple separate arguments, invalid object literals without keys, or mismatched variable names and data types (string instead of array).