Skip to content

Commit c74f720

Browse files
committed
debugged examples using specified conversion types, added additional examples to include implicit and explicit conversion
git push https://github.com/kazzjax/software-dev-course-explicit-and-implicit-conversion-in-javascript main
1 parent ce92942 commit c74f720

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

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

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

2121

22-
let result = "5" - 2;
23-
console.log("The result is: " + result);
22+
let result = Number("5") - 2; //this code works correctly as is, but I can also convert the string to a numeric value
23+
console.log("The result is: " + result);//displays 3
2424

25-
let isValid = Boolean("false");
25+
26+
let isValid = false;//previously had a string of the word false using Boolean() but was still considered truthy due to if(INPUT)
2627
if (isValid) {
27-
console.log("This is valid!");
28+
console.log("This is valid!");//does not display
29+
} else {//added else to display if value is intentionally false
30+
console.log("This is invalid")//displays This is invalid
2831
}
2932

30-
let age = "25";
33+
34+
let age = Number("25"); //this avoids concatenation by converting string to number
3135
let totalAge = age + 5;
3236
console.log("Total Age: " + totalAge);
37+
38+
39+
let loginPass;
40+
if (loginPass); //this is marked as undefined, but since there is an entry here it results in truthy
41+
console.log("Access Granted");
42+
43+
44+
let groupId = 55400;//if these remain number values, the + will erroneously add the values together
45+
let policyNumber = 2626801;
46+
console.log("Member ID: " + String(groupId) + String(policyNumber));//Displays Member ID: 554002626801

0 commit comments

Comments
 (0)