Data Types in JavaScript
6.1 Data Types in JavaScript
Primitive Data Types - These hold only single values
- String - ( "Hello" , 'JavaScript' )
- Number - ( 10 , 3.14 , -5 )
- Boolean - ( true , false )
- Undefined - ( A declared variable with no value )
- Null - ( An intentional empty value )
- BigInt - ( Very large number )
- Symbol - ( Unique and Immutable value )
Example of different Data Types
Non-Primitive (Reference) Data Types - These hold primitive values
- Object
- Array
- Function
To be discussed later
The typeof Operator - to check the type of any variable
Usage of typeof Operator:
Caution: null is intentional, undefined is not
- String - ( "Hello" , 'JavaScript' )
- Number - ( 10 , 3.14 , -5 )
- Boolean - ( true , false )
- Undefined - ( A declared variable with no value )
- Null - ( An intentional empty value )
- BigInt - ( Very large number )
- Symbol - ( Unique and Immutable value )
Example of different Data Types
dataTypes.js
1let str = "Oliver" // String
2let num = 42 // Number
3let isStudent = true // Boolean
4let x // Undefined
5let y = null // Null
Non-Primitive (Reference) Data Types - These hold primitive values
- Object
- Array
- Function
To be discussed later
The typeof Operator - to check the type of any variable
Usage of typeof Operator:
typeof.js
1console.log(typeof "Oliver") // string
2console.log(typeof 10) // number
3console.log(typeof true) // boolean
4console.log(typeof undefined) // undefined
5console.log(typeof null) // object (weird quirk!)
Caution: null is intentional, undefined is not