Skip to content

Commit e187cef

Browse files
author
Mayra
committed
Updated edits lesson
1 parent ce92942 commit e187cef

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;//number convsersion of string;
2323
console.log("The result is: " + result);
2424

25-
let isValid = Boolean("false");
25+
let isValid = Boolean("false");//the if statement executes beacuse the string "false" is a truly value
2626
if (isValid) {
2727
console.log("This is valid!");
2828
}
2929

3030
let age = "25";
31-
let totalAge = age + 5;
31+
let totalAge = Number(age) + 5;// + operater triggers string concatenation, converts 5 into string and add it to string variable age"25" to yield string 255
32+
//added explicit type conversion Number() to variable (age) to change data type from string to number
3233
console.log("Total Age: " + totalAge);
34+
35+
//added explicit example with edge case of 0
36+
let compliment = Boolean (totalAge == 0);
37+
if(compliment){
38+
console.log("You are a newborn baby!");
39+
}
40+
41+
let compliment2 = "You are" + " " + age + " " + "years young!";//added implicit example
42+
console.log(compliment2);

0 commit comments

Comments
 (0)