-
-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy path5-default.js
More file actions
38 lines (32 loc) · 632 Bytes
/
5-default.js
File metadata and controls
38 lines (32 loc) · 632 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
// ES6 style for default parameter values
//
function fnNew(a, b = 'Hello', c = 5) {
console.dir({ a, b, c });
}
fnNew(1, 2, 3);
fnNew(1, 2);
fnNew(1);
fnNew();
// Old style for default parameter values
//
function fnOld(a, b, c) {
b = b || 'Hello';
c = c || 5;
console.dir({ a, b, c });
}
fnOld(1, 2, 3);
fnOld(1, 2);
fnOld(1);
fnOld();
// Hash style for default parameter values
//
function fnHash(args) {
args.a = args.a || [7, 25, 10];
args.b = args.b || 'Hello';
args.c = args.c || 100;
console.dir(args);
}
fnHash({ a: [1, 2, 3], b: 'Hi', c: 3 });
fnHash({ b: 'World' });
fnHash({ c: 7 });