Question · JavaScript and TypeScript course · Module 2: Functions, Arrays and Objects

Destructuring - Alias and Default Value

What does the expression const { id: sensorId, status = 'active' } = sensor mean?

Answer options

  • Creates variables id and status with values sensorId and 'active'
  • Creates variable sensorId with value sensor.id, and status with default value 'active' if it doesn't exist
  • Assigns 'active' to sensor.status and sensorId to sensor.id
  • Creates an object with keys sensorId and status
Show the answer

Correct answer:

  • Creates variable sensorId with value sensor.id, and status with default value 'active' if it doesn't exist