• 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
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

  • Converting Object to Array in JavaScript

  • JavaScript Module Cheatsheet

  • JS Essentials: Falsy Values

  • Math.sign: How to Check if Number is Negative or Positive in JavaScript


Top Tidbits

  • CSS empty Selector

    CSS empty Selector

  • Centering Element With Flexbox

    Centering Element With Flexbox

  • Converting Object to Array in JavaScript

    Converting Object to Array in JavaScript

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

    How to Pad a String with padStart and padEnd in JavaScript

  • JS Essentials: Falsy Values

    JS Essentials: Falsy Values

  • CSS only-child

    CSS only-child

  • 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

  • #BlackLivesMatter

  • Building my New Site with Tailwind CSS

  • Building my New Site with VuePress

  • Testing Non-Exported Functions in JavaScript with Rewire


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 2022. Samantha Ming