1function say(message='Hi') {
2 console.log(message);
3}
4say(); // 'Hi'
5say(undefined); // 'Hi'
6say('Hello'); // 'Hello'
7
8
9function date(d = today()) {
10 console.log(d);
11}
12function today() {
13 return (new Date()).toLocaleDateString("en-US");
14}
15date();
16
17
18function add(x = 1, y = x, z = x + y) {
19 return x + y + z;
20}
21console.log(add()); // 4
22
1function multiply(a, b) {
2 b = (typeof b !== 'undefined') ? b : 1
3 return a * b
4}