We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7d1d933 commit 6f64559Copy full SHA for 6f64559
part1 (Basics)/Type-Conversion-Coercion/type-conversion-coercion.js
@@ -0,0 +1,31 @@
1
+/*
2
+INFO: What is Type Conversion ?
3
+Changing one data type into another.
4
+Happens in two ways:
5
+1. Explicit (Manual) - You converts it yourself
6
+2. Implicit (Automatic) - Js does it for you
7
+*/
8
+
9
+// Explicit Conversion (Manual)
10
+String(123); // "123"
11
+Number("123"); // 123
12
+Boolean(0); // false
13
14
+// Implicit Conversion (Automatic by JS)
15
+"5" + 1; // "51"
16
+true + "3"; // "true3"
17
+"5" - 1; // 4
18
+true + true; // 2
19
+false - true; // -1
20
+if ("") {
21
+} // false
22
+if ("hello") {
23
+} // true
24
+[] + []; // ""
25
+[] + {}; // "[object object]"
26
+{
27
+}
28
++[]; // 0
29
30
+null + 1; // 1
31
+undefined + 1; // NaN
0 commit comments