Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Destructuring and Spread | Section
JavaScript Essentials for Backend

bookDestructuring and Spread

Svep för att visa menyn

Destructuring allows you to extract values from objects and arrays into variables.

const user = {
  name: "John",
  age: 25
};

const { name, age } = user;

Now you can use name and age directly instead of accessing them through the object.

You can also use destructuring with arrays:

const numbers = [10, 20];

const [first, second] = numbers;

The spread operator (...) is used to copy or merge data.

const user = { name: "John" };

const updatedUser = {
  ...user,
  age: 25
};

This creates a new object with all existing data plus new values.

Destructuring and spread are commonly used when working with data, especially in backend code where objects are passed and modified frequently.

question mark

What will this code output?

Vänligen välj det korrekta svaret

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 10

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Avsnitt 1. Kapitel 10
some-alt