We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7c75ad9 commit fb4a3e1Copy full SHA for fb4a3e1
2 files changed
js-coding-technique/ternary-operator.js
@@ -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
js-coding-technique/variables-shorthand.js
@@ -0,0 +1,9 @@
+let a;
+let b;
+let c = 6;
+let a,
+ b,
+ c = 6;
0 commit comments