Skip to content

Commit efc5559

Browse files
author
Shakhruh Hasanov
committed
Lesson 3
1 parent ce92942 commit efc5559

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

explicit-and-implicit-conversion-in-javascript.js renamed to Main.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ 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 one example of implicit type conversion
2323
console.log("The result is: " + result);
2424

25-
let isValid = Boolean("false");
25+
let isValid = Boolean("false" === "true");//this also explicit conversion. boolean method onlu converts empty, null,Nan, 0 to false. It does not convert string
26+
//console.log(isValid);
2627
if (isValid) {
27-
console.log("This is valid!");
28+
console.log("This is valid!");//this should not run
29+
}
30+
else{
31+
console.log("This is not valid!");
2832
}
2933

3034
let age = "25";
31-
let totalAge = age + 5;
35+
let totalAge = Number(age) + 5;//this is explicit type conversion
3236
console.log("Total Age: " + totalAge);

0 commit comments

Comments
 (0)