4343- The ` typeof ` operator returns a string indicating the type of the operand
4444
4545``` js
46- typeof 50 - " number"
47- typeof " text" - " string"
48- typeof true - " boolean"
49- typeof undefined - " undefined"
50- typeof function (){} - " function"
51- typeof 10n - " bigint"
52- typeof Symbol () - " symbol"
53- typeof [1 , 2 ] - " object"
54- typeof {} - " object"
55-
56- typeof NaN - " number" // NaN is Not a Number
57- typeof undeclaredVar - " undefined" // undeclaredVariable is never declared
58- typeof Infinity - " number" // Infinity, -Infinity, -0 are all valid numbers in JavaScript
59- typeof null - " object" // This stands since the beginning of JavaScript
60- typeof / regex/ - " object" // regular expressions start and end with '/' in literal form
46+ typeof 50 // "number"
47+ typeof " text" // "string"
48+ typeof true // "boolean"
49+ typeof undefined // "undefined"
50+ typeof function (){} // "function"
51+ typeof 10n // "bigint"
52+ typeof Symbol () // "symbol"
53+ typeof [1 , 2 ] // "object"
54+ typeof {} // "object"
55+
56+ typeof NaN // "number" // NaN is Not a Number
57+ typeof undeclaredVar // "undefined" // undeclaredVariable is never declared
58+ typeof Infinity // "number" // Infinity, -Infinity, -0 are all valid numbers in JavaScript
59+ typeof null // "object" // This stands since the beginning of JavaScript
60+ typeof / regex/ // "object" // regular expressions start and end with '/' in literal form
6161```
6262
6363###### Notes
@@ -75,16 +75,16 @@ Arrays and functions are sub type of objects
7575
7676``` js
7777// numbers and strings
78- 1 + ' 2' ; // 12
79- 1 + 2 + ' 3' ; // 33
80- 1 + 2 + ' 3' + ' 4' ; // 334
81- 1 + ' One' ; // 1One
78+ 1 + ' 2' ; // 12
79+ 1 + 2 + ' 3' ; // 33
80+ 1 + 2 + ' 3' + ' 4' ; // 334
81+ 1 + ' One' ; // 1One
8282
8383// strings and numbers
84- ' 1' + 2 ; // 12
85- ' 1' + ' 2' + 3 ; // 123
86- ' 1' + ' 2' + 3 + 4 ; // 1234
87- ' 1' + ' 2' + (3 + 4 ); // 127
84+ ' 1' + 2 ; // 12
85+ ' 1' + ' 2' + 3 ; // 123
86+ ' 1' + ' 2' + 3 + 4 ; // 1234
87+ ' 1' + ' 2' + (3 + 4 ); // 127
8888' One' + 1 ; // One1
8989
9090// mix of string and numbers
@@ -141,11 +141,11 @@ const str = "12";
141141
142142Number (str); // 12
143143+ str // 12
144- parseInt (str) // 12
144+ parseInt (str) // 12
145145```
146146
147147###### Notes
148- If the number is floating, ` parseFloat ` can be used
148+ If the number is floating, ` parseFloat ` can be used. ` parseInt ` and ` parseFloat ` are the methods present on the ` Number ` object also
149149
150150###### References
151151- https://javascript.info/type-conversions
@@ -186,37 +186,37 @@ The big integers cannot be operated directly with normal number datatype. `10n +
186186``` js
187187const num1 = 10 , num2 = 20 ;
188188
189- true || false ; // true
190- false || false ; // false
191- false || num1; // 10
192- 0 || num2; // 20
193- " text" || true // "text"
194- num1 > 0 || num2 < 0 // true
189+ true || false ; // true
190+ false || false ; // false
191+ false || num1; // 10
192+ 0 || num2; // 20
193+ " text" || true // "text"
194+ num1 > 0 || num2 < 0 // true
195195```
196196
197197``` js
198198const num1 = 10 , num2 = 20 ;
199199
200- true && false ; // false
201- false && false ; // false
200+ true && true ; // true
201+ true && false ; // false
202202true && num1; // 10
203203num1 && num2; // 20
204204" text" && (num1 + num2) // 30
205205num1 > 0 && num2 < 0 // false
206206```
207207
208208``` js
209- undefined ?? 10 ; // 10
210- null ?? 20 ; // 20
211- false ?? num1; // false
212- 0 ?? num2; // 0
209+ undefined ?? 10 ; // 10
210+ null ?? 20 ; // 20
211+ false ?? num1; // false
212+ 0 ?? num2; // 0
213213` ` `
214214
215215` ` ` js
216- !! 10 ; // true
217- !! {}; // true
218- !! " " ; // false
219- !! 0 ; // false
216+ !! 10 ; // true
217+ !! {}; // true
218+ !! " " ; // false
219+ !! 0 ; // false
220220` ` `
221221
222222###### Notes
0 commit comments