TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
JavaScript / Chapter 14 of 60~12 min • Beginner
Chapter 14JavaScript

Destructuring and spread

Destructuring extracts named properties or positional array values. Spread syntax copies enumerable own properties into a new object or expands array elements. These copies are shallow, so nested objects may still be shared.

How it works

Step-by-step walkthrough

  1. Create an options object
  2. Extract a property
  3. Override a copied value

Example

JavaScript
const defaults = { browser: 'chromium', retries: 0 };
const { browser } = defaults;
const ci = { ...defaults, retries: 2 };
console.log(browser, ci.retries);
Expected result: chromium 2
💡 Point to remember
Put overrides after spread so they replace the earlier value.

✎ Your practice task

Create a new options object with firefox.

Knowledge check

Is object spread a deep clone?

🌐 Continue learning