1/9
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
How to know the type of a JS variable?
typeof operator
Data types
Primitive → store a single value
Non-primitive → store multiple and complex values
Primitive data types
String
Number
Bigint → above number limits
Boolean
Undefined → declared but not assigned
Null → Non-existent, invalid value
Symbol → ES6 anonymous, unique value
typeof of primitive types
typeof "John Doe" // Returns "string"
typeof 3.14 // Returns "number"
typeof true // Returns "boolean"
typeof 234567890123456789012345678901234567890n // Returns bigint
typeof undefined // Returns "undefined"
typeof null // Returns "object" (kind of a bug in JavaScript)
typeof Symbol('symbol') // Returns Symbol
Non-primitive types
Object → store collection of data
→ any data type that’s not primitive is an object in JS
Hoisting
default behavior where all var and function declarations are moved on top