Skip to content

Commit 6d987af

Browse files
committed
all changes made
1 parent ce92942 commit 6d987af

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,29 @@ Use console.log() to clearly show the before-and-after type conversions.
1919
*/
2020

2121

22-
let result = "5" - 2;
22+
let result = Number("5") - 2;
23+
//Turned string 5 into an integer 5, same result.
2324
console.log("The result is: " + result);
2425

25-
let isValid = Boolean("false");
26+
let isValid = false;
27+
//Strings are considered a true value, having "false" would always make it true.
2628
if (isValid) {
2729
console.log("This is valid!");
2830
}
2931

3032
let age = "25";
31-
let totalAge = age + 5;
33+
let totalAge = (Number(age)) + 5;
34+
//Adding the Number() explicit converison turns the age string into an integer allowing for total age to calculate.
3235
console.log("Total Age: " + totalAge);
36+
37+
38+
let bigNumber = "175" - 27;
39+
console.log(bigNumber);
40+
//This is my implicit code.
41+
42+
console.log(String(null));
43+
//Here are some explicit examples.
44+
let notANumber;
45+
console.log(notANumber)
46+
47+
console.log(Number("A"))

0 commit comments

Comments
 (0)