Skip to content

Commit 100e4d6

Browse files
committed
coding techniques.
1 parent fb4a3e1 commit 100e4d6

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

js-coding-technique/If-presence.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Longhand:
2+
let likeJavaScript;
3+
4+
if (likeJavaScript === true) {
5+
// something here
6+
}
7+
8+
// Shorthand:
9+
10+
if (likeJavaScript) {
11+
// something here
12+
}
13+
14+
// Longhand:
15+
16+
let variableName;
17+
if (variableName !== true) {
18+
// do something...
19+
}
20+
21+
// Shorthand:
22+
23+
let variableName;
24+
if (!variableName) {
25+
// do something...
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Longhand:
2+
3+
// if (
4+
// variable1 !== null ||
5+
// variable1 !== undefined ||
6+
// variable1 !== 'something'
7+
// ) {
8+
// let variable2 = variable1;
9+
// }
10+
11+
// Shorthand:
12+
// const variable2 = variable1 || 'new';
13+
14+
// example
15+
16+
let variable1;
17+
let variable2 = variable1 || 'love js';
18+
console.log(variable2 === 'love js'); // prints true
19+
20+
variable1 = 'foo';
21+
variable2 = variable1 || 'love js';
22+
console.log(variable2); // prints foo

0 commit comments

Comments
 (0)