main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function add(x, y) {
  if (y === undefined) {
    y = 5 // default value if only one argument -- verbose
  }
  return x + y
}

console.log(add(1, 0))

function add_v2(x, y) {
  y = y || 5 // default value if only one argument -- but zero is falsy edge case
  return x + y
}

console.log(add_v2(1, 0))

function add_ES6(x, y=5) {
  return x + y
}

console.log(add_ES6(1, 0))
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie