82

October 10th, 2018 ×

Top 18 New Things in JS - Part 2

or

In this episode Wes and Scott continue the discussion of their favorite top 18 new things in Javascript.

Freshbooks - Sponsor

Get a 30 day free trial of Freshbooks at freshbooks.com/syntax and put SYNTAX in the "How did you hear about us?" section.

Graph CMS - Sponsor

GraphCMS is trying to be the world’s most developer friendly CMS. It's a great way to build a GraphQL API without having to write a custom GraphQL server. Try out the API-first CMS of the future today at graphcms.com/syntaxfm.

Show Notes

3:30

  • Spread
const array1 = [1, 2, 3]
const array2 = [0, ...array1]

8:40

  • Rests
const teams = [player1, player2, player3]
const [leader, ...members] = teams

11:54

  • Arrow Functions
const add = (x, y) => {
  return x + y
}
// equal to
const add = (x, y) => x + y

15:48

  • Default Function Arguments
function mul(x, y = 1) {
  return x * y
}
mul(2, 3) // 2 * 3 = 6
mul(2) // 2 * 1 = 2

19:47

  • Named params
function ({ array, element }) {
  return [element, ...array]
}

21:26

  • Modules
// @ a.js
export const param = 1
const defaultParam = 2
export default defaultParam

// @ b.js
import defaultParam, { param } from './a'

// rename import module
import newDefaultParam from './a' // rename default export directly
import { param as newParam} from './a' // use `as` for rename

35:35

  • Classes
class Polygon {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }

  get area() {
    return this.calcArea();
  }
  
  calcArea() {
    return this.height * this.width;
  }
}

class Square extends Polygon {
  ...
}

41:54

  • Things we never use
await const users = fetchUser().catch(e => ...)

for(let element of array) { ... }

const set1 = new Set([1, 2, 3, 4, 5]);

××× SIIIIICK ××× PIIIICKS ×××

Shameless Plugs

Tweet us your tasty treats!

Share

Play / pause the audio
Minimize / expand the player
Mute / unmute the audio
Seek backward 30 seconds
Seek forward 30 seconds
Increase playback rate
Decrease playback rate
Show / hide this window