• Samantha Ming Logo Samantha Ming
  • Tidbits
  • Blog
  • Courses
  • Contact
Samantha Ming Logo
  • Home
  • Tidbits
  • Blog
  • Courses
  • Contact

  • Flexbox30
  • Newsletter
  • About
  • Invite me to speak
  • Become a sponsor

# Swapping Variables With Destructuring

ES6 Destructuring to the rescue πŸ†

Easily swap two variables using ES6 destructing. It’s a great way to fix #Oscars Best Picture mix-ups 😜

let oscar = 'La La Land';
let nominee = 'Moonlight';

[oscar, nominee] = [nominee, oscar];

console.log(oscar); // Moonlight
console.log(nominee); // La La Land
Code snippet of Swapping Variables With Destructuring
Download HD Image
Next Tidbit
Trick to Adding String and Number in JavaScript
  • Share to Twitter Twitter
  • Share to Facebook Facebook
  • Share to LinkedIn LinkedIn
  • Share to Reddit Reddit
  • Share to Hacker News Hacker News
  • Email Email

Related Tidbits

  • 4 Ways to Combine Strings in JavaScript

  • Checking if a string contains substring in JavaScript

  • JavaScript Object.fromEntries()

  • How to check if Variable is an Array in JavaScript

Code snippet of Swapping Variables With Destructuring

Top Tidbits

  • Convert Iterable to Array using Spread in JavaScript

    Convert Iterable to Array using Spread in JavaScript

  • Highlight Text With HTML Mark Tag

    Highlight Text With HTML Mark Tag

  • padEnd String Method in JavaScript

    padEnd String Method in JavaScript

  • 3 Ways to Set Default Value in JavaScript

    3 Ways to Set Default Value in JavaScript

  • Strike Through Using HTML

    Strike Through Using HTML

  • Checking if a string contains substring in JavaScript

    Checking if a string contains substring in JavaScript

  • hi
  • javascript
  • html
  • css
  • vue
  • console
  • array
  • object
  • es6
  • string
  • number
  • code recipes

Courses

  • Flexbox30

    - Learn Flexbox with 30 Code Tidbits ✨

  • CodeTidbits30

    - 30 days of the best JS, CSS, HTML tidbits πŸŽ„

  • Web Basics

    - Web Basics Explained with Tidbits 🍎

  • Pictorials

    - Step by Step Code Tutorials πŸ‘£


Top Articles

  • My Top 3 Favorite ES6 Courses

  • New features in 2.0

  • Testing Non-Exported Functions in JavaScript with Rewire

  • Journal Entry #1: Take Action!


Fresh Tidbits

  • Code snippet on HTML abbr Tag

    HTML abbr Tag

  • Code snippet on How to Pad a String with padStart and padEnd in JavaScript

    How to Pad a String with padStart and padEnd in JavaScript

  • Code snippet on Avoid Empty Class in Vue with Null

    Avoid Empty Class in Vue with Null

  • Code snippet on Fix Text Overlap with CSS white-space

    Fix Text Overlap with CSS white-space

  • Code snippet on How to Check if Object is Empty in JavaScript

    How to Check if Object is Empty in JavaScript

  • hi
  • Home
  • Tidbits
  • Blog
  • Courses
  • Newsletter
  • About
  • Contact

  • What I use
  • Flexbox30
  • Pictorials
  • Web Basics
  • Invite me to speak
  • Become a sponsor
Β© Copyright 2025. Samantha Ming