Skip to content

Commit fb4a3e1

Browse files
committed
JavaScript Shorthand Coding Techniques..
1 parent 7c75ad9 commit fb4a3e1

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Longhand:
2+
const a = 25;
3+
let answer;
4+
5+
if (a > 11) {
6+
answer = 'greater than 10';
7+
} else {
8+
answer = 'less than 10';
9+
}
10+
11+
// Shorthand:
12+
const answer = a > 10 ? 'greater than 10' : 'less than 10';
13+
console.log(answer);
14+
15+
// We can also try this
16+
const answer =
17+
a > 10 ? 'greater than 10' : a < 5 ? 'less than 5' : 'between 5 and 10';
18+
console.log(answer);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Longhand:
2+
let a;
3+
let b;
4+
let c = 6;
5+
6+
// Shorthand:
7+
let a,
8+
b,
9+
c = 6;

0 commit comments

Comments
 (0)