File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments