File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -56,3 +56,32 @@ const value2 = 1;
5656// answer is 11 here as JavaScript will treat the evaluation as concatenation of two String not adding numbers e.g 1 + 1 is 2.
5757console .log (value1 + value2)
5858```
59+
60+ ## Converting String to Number
61+
62+ ``` javascript
63+ let stringNum = ' 150' ;
64+
65+ console .log (parseInt (` ${ 2020 + 1 } ` )); // 2021
66+ console .log (parseInt (stringNum)); // 150
67+ console .log (parseInt (' eight' )); // NaN
68+ console .log (parseInt (' 0xF' )); // hexadecimal number
69+ ```
70+
71+ ## Converting String to Float
72+
73+ ``` javascript
74+ console .log (parseFloat (2.50 + 0.13 )); // 2.63
75+ console .log (parseFloat (' five' )); // NaN
76+ ```
77+
78+ ## Converting Number to String
79+
80+ ``` javascript
81+ let number = 150 ;
82+ let floatValue = 1.50 ;
83+
84+ console .log (number .toString ()); // '150'
85+ console .log (floatValue .toString ()); // '1.50'
86+ console .log ((100 ).toString ()); // '100'
87+ ```
You can’t perform that action at this time.
0 commit comments