What the ES6?

What is ES6?

History of ECMA-262.

  • Mocha (1993) → LiveScript (1995) JavaScript (1995) → JScript (1996) → ECMA Script open spec (1997).
     
  • v1 (1997) and v2 (1998) vision for unified script language.
     
  • v3 (1999) adds regular expressions and other features.
     
  • v4 (💀) never released.
     
  • v5 (2009) and v5.1 (2015)  adds 'strict mode', JSON parsing, editorial changes and minor features.

ES6 is a huge deal!

ES Harmony Approach.

Is there an ES7+?

Enter Transpilation

#### Conclusion on bind
- Get more feedback from users on Babel

Supporting older ES

Key ES6 Changes

  • 📜 Strings
  • 💾 Variables
  • ➡️ Functions
  • 📦 Arrays and Objects
  • 🎡 Loops
  • 🐸 Classes
  • 💍  Promises
  • 🚚 Modules

📜 Strings

  • New methods: startsWith, endsWidth, includes and repeat.
     
  • For template literals uses back-ticks and not quotes.
     
  • Allow embedded expressions via ${} syntax.
     
  • Tags automatically assemble string into arguments.

💾 Variables

  • Adds let and const in addition to existing var.
     
  • Neither can not be re-declared.
     
  • Scoped to functions and blocks (basically inside {}).
     
  • Neither can be hoisted.
     
  • const can not be re-assigned (can still be mutated).
     
  • Preference depends on approach (OOP vs. functional).

➡️ Functions

  • Shorter arrow syntax.
     
  • Do not need parentheses if single parameter.
     
  • Does not need curly brackets if single expression.
     
  • Objects can be returned by encasing in parantheses.
     
  • Does not have its own lexical this.
     
  • Has no native arguments array.

📦 Arrays and Objects

  • Property and method assignment shorthand.
     
  • Object and array destructuring.
     
  • Array and parameter rest operator. (Object rest ES7)
     
  • Array from method for nodes list and arguments.
     
  • Array find method useful when array of objects.

🎡 Loops

  • ES5 For loop.
     
  • For of loop for arrays.
     
  • For in loop for objects.
     
  • Caveats of using For in on objects.
     
  • Generators.
     
  • Custom iterator.

 

🐸 Classes

  • Classes in ES5.
     
  • Classes in ES6.
     
  • Symbols.
     
  • Methods: get, set, static and regular methods.

 

💍​ Promises

  • ES5 callbacks (christmas tree of death).
     
  • Promise pass function with 'resolve' and 'reject' params.
     
  • Outside main flow, need '.catch' to handle errors.
     
  • Chain promises: '.then' and resolve all: 'Promise.all()'
     
  • Terminating promises.
     
  • Using fetch for AJAX and assets.

🚚​ Modules

  • Named imports and exports. (tree-shaking).
     
  • Can use 'as' to rename named imports.
     
  • Default imports and exports.
     
  • Arrow methods only in ES7 (manually 'this.bind').
     
  • '<scripts type="modules">' and '<scripts nomodules>'
     
  • Other types of JS modules: CommonJS, AMD and UMD.

 

Download Example

git clone https://github.com/schalkventer/humans-in-space.git
  1. Install NodeJS.
     
  2. Download via browser or clone example via Git:


     
  3. Open either 'es-modules' or 'parcel-transpilation' via terminal, command-line or Powershell.
     
  4. Run 'npm install & npm start'.

 

Shoutout: Codebridge

Get in touch

 

 

What the ES6?

By Schalk Venter

What the ES6?

A deep dive into what exactly ES6 is and some core features it introduces to the JavaScript language.

  • 1,207