Skip to content

Commit 802ac48

Browse files
author
Michael
committed
debugged OG code and added 1 example of implicit and 1 example of explicit data conversion
1 parent ce92942 commit 802ac48

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

explicit-and-implicit-conversion-in-javascript.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,23 @@ Use console.log() to clearly show the before-and-after type conversions.
2222
let result = "5" - 2;
2323
console.log("The result is: " + result);
2424

25-
let isValid = Boolean("false");
25+
let isValid = Boolean(1); // changed to a value to indicate a truthy
2626
if (isValid) {
2727
console.log("This is valid!");
2828
}
2929

3030
let age = "25";
31-
let totalAge = age + 5;
31+
let totalAge = Number(age) + 5; // changed age to a number instead of string
3232
console.log("Total Age: " + totalAge);
33+
34+
35+
//explicit data convert a number to a string explicit data
36+
let num = 981;
37+
let str = String(num);
38+
console.log(str);
39+
console.log(typeof str);
40+
41+
// implicit data convert
42+
if (null){
43+
console.log("this is falsy") // will not run
44+
}

0 commit comments

Comments
 (0)