Saturday, October 19, 2019

JavaScript ES6 / ES2015 - My Notes

JavaScript ES6 / ES2015 - My Notes

Using ES6 in Prod

  • Supported by modern but not by older browsers
  • So, ES6 needs to be transpiled or multipiled in prod

The let and const

  • const - generates an error when attempted to change value
  • both - block-scoped while var was function scoped (a block is just {...})
  • Now, instead of using IIFE, we can use a block. Variables (and function expressions assigned to variables) marked const or let will be private. While those marked with var will be public.

Strings

  • Template liters (note back-ticks): His name is ${firstName} ${lastName}.

Arrow Functions

  • If we have an array arr1, then arr1.map(el => 2 * el) will return an array of doubled numbers.
  • In fuller format:
    arr1.map((elem, index) => {
      ....
      return ...
    })
  • Arrow functions don't have their own this. They use the this of the function they written in - it's called lexical this.