JavaScript Data Types

JavaScript Data Types

JavaScript has two categories of data types:


1. Primitive Data Types

Primitive types are simple, immutable (cannot be changed), and stored directly in memory.

Data Type Example Description
String "Hello" Text data
Number 10, 10.5 Numeric values (integer + float)
BigInt 123n Very large numbers
Boolean true / false Logical values
Undefined let a; Variable declared but not assigned
Null let a = null; Empty or intentionally no value
Symbol Symbol("id") Unique and immutable value

Examples:



 


2. Non-Primitive (Reference) Types

These are objects and stored by reference.

Type Example
Object {name:"John", age:30}
Array ["apple", "banana"]
Function function hello(){...}

Example:



 


📌 Type Checking Using typeof



 

⚠️ Note: typeof null returns "object" — this is a known JavaScript mistake from early versions.


🧠 Special Notes

  • Strings can use " ", ' ' or (template literals):



 

  • JavaScript Numbers are always floating-point:



 


🚀 Summary Table

Category Data Types
Primitive String, Number, BigInt, Boolean, Undefined, Null, Symbol
Non-Primitive Object, Array, Function

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

Leave a Reply

Your email address will not be published. Required fields are marked *