Skip to content

Commit 4a1afba

Browse files
committed
THis is my completed assginment for the type conversion practice
1 parent ce92942 commit 4a1afba

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

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

2121

22-
let result = "5" - 2;
22+
let result = "5" - 2; // This is Correct as 5-2 is 3. THis is an example of implicit conversion
2323
console.log("The result is: " + result);
2424

25-
let isValid = Boolean("false");
25+
let isValid = Boolean(false); // I fixed this so it does not run the statement as it is False.
2626
if (isValid) {
2727
console.log("This is valid!");
2828
}
2929

3030
let age = "25";
31-
let totalAge = age + 5;
31+
let realAge= Number(age); // I converted the string to a number so it does the proper calcualtion instead of a string concatenation
32+
let totalAge = realAge + 5;
3233
console.log("Total Age: " + totalAge);
34+
35+
36+
console.log("5"*"10"); // THis is implicit as the computer automatically converts these strings to numbers
37+
38+
let isLaughing=true;
39+
console.log(isLaughing.toString()); //I explicity made this boolean convert to a string.
40+
41+
let num=NaN;
42+
console.log(Boolean(num)); // Using a edge case, the variable humber is false becuase it is not a number

0 commit comments

Comments
 (0)