Skip to content

Commit 163547a

Browse files
committed
default parameter | Template Literals
1 parent fb72d2f commit 163547a

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Longhand:
2+
3+
function volumeFunc(a, b, c) {
4+
if (b === undefined) b = 3;
5+
if (c === undefined) c = 4;
6+
return a * b * c;
7+
}
8+
9+
// Shorthand:
10+
11+
volumeFunc = (a, b = 3, c = 4) => a * b * c;
12+
13+
volumeFunc(2); //output: 24
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Longhand:
2+
3+
const welcomeMgs = 'You have logged in as ' + firstName + ' ' + lastName + '.';
4+
5+
const dbLink = 'http://' + host + ':' + port + '/' + database;
6+
7+
// Shorthand:
8+
9+
const welcomeMgs = `You have logged in as ${firstName} ${lastName}`;
10+
11+
const dbLink = `http://${host}:${port}/${database}`;
12+
13+
let a = 9;
14+
let b = 10;
15+
console.log(`Nineteen is ${a + b} and
16+
not ${2 * a + b}.`);

0 commit comments

Comments
 (0)