Skip to content

Commit 519a00c

Browse files
committed
Alex's conversions in Javascript
1 parent ce92942 commit 519a00c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ 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 Covers implicit conversion cause JavaScript converts the string to a number for you.*/
2323
console.log("The result is: " + result);
2424

25-
let isValid = Boolean("false");
25+
let isValid = Boolean("false"); /*This is an edge case because non empty strings in java script are always true so even though it says false it is valid.*/
2626
if (isValid) {
2727
console.log("This is valid!");
2828
}
2929

30-
let age = "25";
30+
let age = Number("25"); /*Wrapping this string with a number conversions so that on line 31 the types are the same. This would also be an explicit conversion.*/
3131
let totalAge = age + 5;
3232
console.log("Total Age: " + totalAge);

0 commit comments

Comments
 (0)