Skip to content

Commit 7207c54

Browse files
committed
debugged
1 parent ce92942 commit 7207c54

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ Use console.log() to clearly show the before-and-after type conversions.
2020

2121

2222
let result = "5" - 2;
23-
console.log("The result is: " + result);
23+
let numResult = Number(result)
24+
console.log("The result is: " + numResult); // While the original code did get the correct output due to implicit conversion, this gets it through excplicit conversion.
2425

2526
let isValid = Boolean("false");
2627
if (isValid) {
27-
console.log("This is valid!");
28+
console.log("This is valid!"); // This is correct. Any non-empty string is considered truthy, even the string "false".
2829
}
2930

3031
let age = "25";
31-
let totalAge = age + 5;
32-
console.log("Total Age: " + totalAge);
32+
let numAge = Number(age);
33+
let totalAge = numAge + 5;
34+
console.log("Total Age: " + totalAge); // Strings and numbers are concatenated by the + operator. To fix, I converted the sting "age" into a number.

0 commit comments

Comments
 (0)