Skip to content

Commit ce1b4a0

Browse files
committed
changes done as part of practice
1 parent ce92942 commit ce1b4a0

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/*
2-
32
Part 1: Debugging Challenge
43
The JavaScript code below contains intentional bugs related to type conversion.
54
Please do the following:
@@ -15,18 +14,18 @@ Write their own code that demonstrates:
1514
*We encourage you to:
1615
Include at least one edge case, like NaN, undefined, or null .
1716
Use console.log() to clearly show the before-and-after type conversions.
18-
1917
*/
2018

2119

22-
let result = "5" - 2;
23-
console.log("The result is: " + result);
20+
let result = Number("5" )- 2; // explicit conversion
21+
console.log("The result is: "+result);
2422

23+
// Boolean of any value other than null, "", NaN, undefined, false is true. Hence the string "false" evaluates to true and the console.log is printed.
2524
let isValid = Boolean("false");
2625
if (isValid) {
2726
console.log("This is valid!");
2827
}
2928

3029
let age = "25";
31-
let totalAge = age + 5;
32-
console.log("Total Age: " + totalAge);
30+
let totalAge = Number(age) + 5;// explicit conversion
31+
console.log("Total Age: " + String(totalAge));// explicit conversion

0 commit comments

Comments
 (0)