Multiple variables set to req.body?

Hey all, I could not figure out some of the Boss Machine project - and so looking at the solution code, I noticed a syntax I’d never seen before. Below is the code:

const checkMillionDollarIdea = (req, res, next) => {
  const { numWeeks, weeklyRevenue } = req.body;
  const totalMoney = Number(numWeeks) * Number(weeklyRevenue);
  if (!numWeeks || !weeklyRevenue || isNaN(totalMoney) || totalMoney < 1000000) {
  } else {

In particular, its const { numWeeks, weeklyRevenue } = req.body;

What is this actually doing? Is it a quick way of setting two variables to the same value? Also, would

const numWeeks = req.body;
const weeklyRevenue = req.body;

have achieved the same goal?


its explained here:

under destructing objects.

no, then the code would have to be:

const numWeeks = req.body.numWeeks;
const weeklyRevenue = req.body.weeklyRevenue;

then we can see the destructing assignment does save us a lot of typing!

1 Like