File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -19,14 +19,29 @@ Use console.log() to clearly show the before-and-after type conversions.
19
19
*/
20
20
21
21
22
- let result = "5" - 2 ;
22
+ let result = Number ( "5" ) - 2 ;
23
23
console . log ( "The result is: " + result ) ;
24
+ //Converted result from String to Number
24
25
25
- let isValid = Boolean ( " false" ) ;
26
+ let isValid = Boolean ( false ) ;
26
27
if ( isValid ) {
27
28
console . log ( "This is valid!" ) ;
28
29
}
30
+ //Removed quotation marks to make isValid falsy rather than truthy
29
31
30
32
let age = "25" ;
31
- let totalAge = age + 5 ;
33
+ let totalAge = Number ( age ) + 5 ;
32
34
console . log ( "Total Age: " + totalAge ) ;
35
+ //Converted age from String to Number to make age evaluate as a Number
36
+
37
+ //My own example of implicit type conversion
38
+ let implicitTypeConversion
39
+ if ( ! implicitTypeConversion ) {
40
+ console . log ( "This is invalid!" ) ;
41
+ }
42
+
43
+ //My own example of explicit type conversion
44
+ let explicitTypeConversion
45
+ if ( ! Boolean ( explicitTypeConversion ) ) {
46
+ console . log ( "This is invalid!" ) ;
47
+ }
You can’t perform that action at this time.
0 commit comments