JS · ES6Apr 28, 2017 · 1 min read

Common ES6 Mistakes

Two ES6 gotchas worth knowing: destructuring defaults don't kick in for null (only undefined), and strings are iterables, so new Set('555') gives you a set with one element.

JavaScript
const myObject = {
  emails: null
}

const { emails = [], users = [] } = myObject;

console.log(users.length);   // users is undefined (defaults to []) This returns 0.
console.log(emails.length);  // this will bork; you can't get length of null.

Strings are iterables

JavaScript
const set = new Set('555')
console.log(set);   // {'5'}

More to come as I continue to make more mistakes...