File tree 1 file changed +18
-3
lines changed 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
+ //Turned string 5 into an integer 5, same result.
23
24
console . log ( "The result is: " + result ) ;
24
25
25
- let isValid = Boolean ( "false" ) ;
26
+ let isValid = false ;
27
+ //Strings are considered a true value, having "false" would always make it true.
26
28
if ( isValid ) {
27
29
console . log ( "This is valid!" ) ;
28
30
}
29
31
30
32
let age = "25" ;
31
- let totalAge = age + 5 ;
33
+ let totalAge = ( Number ( age ) ) + 5 ;
34
+ //Adding the Number() explicit converison turns the age string into an integer allowing for total age to calculate.
32
35
console . log ( "Total Age: " + totalAge ) ;
36
+
37
+
38
+ let bigNumber = "175" - 27 ;
39
+ console . log ( bigNumber ) ;
40
+ //This is my implicit code.
41
+
42
+ console . log ( String ( null ) ) ;
43
+ //Here are some explicit examples.
44
+ let notANumber ;
45
+ console . log ( notANumber )
46
+
47
+ console . log ( Number ( "A" ) )
You can’t perform that action at this time.
0 commit comments