Skip to content

Instantly share code, notes, and snippets.

@conanak99
Last active March 9, 2016 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conanak99/7bc7e4cc35221384e26b to your computer and use it in GitHub Desktop.
Save conanak99/7bc7e4cc35221384e26b to your computer and use it in GitHub Desktop.
// Cách cũ, phải check tham số truyền vào rồi xác định giá trị
function multiply(a, b) {
var b = typeof b !== 'undefined' ? b : 1;
return a*b;
}
// Với ES6, chỉ cần sử dụng dấu =
function multiply(a, b = 1) {
return a*b;
}
multiply(5); // 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment