Skip to content

Commit 6f64559

Browse files
feat: add type conversion and coercion
1 parent 7d1d933 commit 6f64559

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
true + true; // 2
30+
null + 1; // 1
31+
undefined + 1; // NaN

0 commit comments

Comments
 (0)