-
-
Save conanak99/7bc7e4cc35221384e26b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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