Types in JavaScript: Complete Guide to JavaScript Data Types with Examples
By Sriram
Updated on Jul 16, 2026 | 5 min read | 1.54K+ views
Share:
All courses
Certifications
More
By Sriram
Updated on Jul 16, 2026 | 5 min read | 1.54K+ views
Share:
Table of Contents
Key Takeaway
This blog walks you through every data type JavaScript supports. You'll see real examples, comparison tables, and the mistakes that trip up most beginners.
Explore upGrad's Data Science programs to build practical skills in data analysis, machine learning, statistics, data visualization, predictive modeling, big data technologies, and real-world problem-solving through hands-on projects, industry tools, and case studies.
Popular Data Science Programs
Every JavaScript program works with data. That data can represent a person's name, a product price, a list of items, or even an entire application state. JavaScript needs a way to recognize what kind of value it's handling, and that's where data types come in. A data type tells the JavaScript engine what kind of value a variable holds and what you can do with it.
JavaScript is a dynamically typed language. That means you don't declare a type when you create a variable. The engine figures it out at runtime, based on the value you assign.
js
let age = 25 // Number
let name = "Riya" // String
let isActive = true // Boolean
Notice something? You never wrote int or string before any of these. JavaScript handled it for you.
Must read: 10 Practical Applications of JavaScript And Career Tips
JavaScript splits its types into two buckets. Primitive types and non-primitive types. This single split explains almost every quirky behavior you'll hit later, including why copying an array doesn't work the way you'd expect.
Primitive values are the simplest values JavaScript can store. They hold the actual value directly instead of pointing to another location in memory. They hold one piece of data and can't be changed once created. JavaScript has seven of them. Each of these does one job well. You won't reach for Symbol or BigInt often as a beginner, but they matter once you're building bigger applications.
Data Type |
Description |
Example |
| String | Stores text enclosed in single quotes, double quotes, or backticks. | let city = "Bengaluru"; |
| Number | Stores numeric values, including integers and decimal numbers. | let price = 499.99; |
| Boolean | Represents one of two values, true or false. | let isLoggedIn = false; |
| Undefined | Indicates a variable has been declared but not assigned a value. | let result; |
| Null | Represents an intentional empty or unknown value. | let user = null; |
| Symbol | Creates a unique, immutable identifier, often used to avoid property name conflicts in objects. | let id = Symbol("userId"); |
| BigInt | Stores integers larger than the maximum safe value supported by the Number type. | let big = 9007199254740993n; |
Primitive values store data directly. Reference types work differently. Instead of storing the actual value, they store a reference to a location in memory where the data exists. This approach makes it possible to work with larger and more complex data structures without copying every value each time they're assigned or passed around. Non-primitive types, also called reference types, can hold collections of values and can change after creation.
Non-Primitive Data Type |
Description |
Example |
| Object | Stores related data as key-value pairs. | let user = { name: "Amit", age: 28 }; |
| Array | Stores an ordered collection of values. | let colors = ["red", "green", "blue"]; |
| Function | Represents a reusable block of code. In JavaScript, functions are also objects. | function greet() { return "Hello!"; } |
Arrays and functions are technically objects under the hood. Run typeof [] and you'll get "object", not "array".
Must read: Applications of JavaScript
Data Science Courses to upskill
Explore Data Science Courses for Career Progression
The real difference between primitive and non-primitive values appears when you copy, compare, or modify them. If you've ever wondered what is the difference between primitive and reference types in JavaScript, the answer lies in how these values are stored and handled in memory. Understanding this concept is essential when learning types in JavaScript because it explains why two variables sometimes stay independent and sometimes affect each other unexpectedly.
Primitive values store the actual data inside the variable. Reference values store the memory address where the data exists. Primitive and non-primitive types behave differently when you copy them, compare them, or pass them into a function.
Feature |
Primitive |
Non-Primitive |
| Storage | Stored directly in the variable | Stored as a reference (memory address) |
| Copying | Creates a full independent copy | Copies the reference, not the data |
| Mutability | Immutable | Mutable |
| Comparison | Compared by value | Compared by reference |
| Example | let a = 5; let b = a; | let obj1 = {}; let obj2 = obj1; |
Try this in your console.
let a = 5
let b = a
b = 10
console.log(a) // 5, unaffected
let obj1 = { count: 1 }
let obj2 = obj1
obj2.count = 99
console.log(obj1.count) // 99, both point to the same object
That's the whole story of primitive vs non primitive data types in JavaScript in two snippets. If you change the copy, the primitive stays put, but if you change the copy of an object, and the original changes too, because both variables point at the same spot in memory.
Do read: JavaScript Free Online Course With Certification
JavaScript is a loosely typed language, which means it can automatically convert one data type into another when needed. This process is called type coercion. It helps JavaScript perform operations on values of different types, but it can also lead to unexpected results if you don't understand how it works.
There are two types of type coercion in JavaScript.
Implicit type coercion happens automatically. JavaScript decides that a value needs to be converted before performing an operation.
For example:
console.log("10" + 5);
Output:
105
Since one operand is a string, JavaScript converts the number 5 into the string "5" and joins them together.
Now look at this example.
console.log("10" - 5);
Output:
5
Here, JavaScript converts the string "10" into the number 10 because subtraction only works with numeric values.
Another example is with Boolean values.
console.log(true + 2);
Output:
3
JavaScript treats true as 1 and false as 0 during arithmetic operations.
Sometimes you may want to control the conversion yourself. This is known as explicit type coercion or type conversion.
JavaScript provides built-in functions to convert values.
Number("25"); // 25
String(100); // "100"
Boolean(1); // true
Boolean(0); // false
Explicit conversion makes your code easier to read because the conversion is intentional rather than automatic.
Expression |
Result |
Explanation |
| "10" + 5 | "105" | Number is converted to a string before concatenation. |
| "10" - 5 | 5 | String is converted to a number before subtraction. |
| true + 2 | 3 | true is converted to 1. |
| false + 5 | 5 | false is converted to 0. |
| null + 1 | 1 | null is treated as 0 in arithmetic operations. |
| undefined + 1 | NaN | undefined cannot be converted into a valid number. |
Here are the best practices:
Understanding how type coercion works helps you predict JavaScript's behavior, reduce unexpected bugs, and write cleaner, more reliable code.
Build job-ready expertise in data science, machine learning, business analytics, and Agentic AI with upGrad's Professional Certificate Programme in Data Science & Agentic AI from IIIT Bangalore. Learn Python, SQL, Power BI, RAG, and AI workflows through hands-on projects, real-world case studies, and an industry-focused capstone designed for practical problem-solving.
Here are examples to help you understand JavaScript better. Let's look at how these types show up in actual code you'd write.
User profile object
const profile = {
name: "Sneha",
age: 24,
isVerified: true
}
Shopping cart array
const cart = ["Laptop", "Mouse", "Keyboard"]
Price using Number
const price = 1299.5
Login state using Boolean
let loggedIn = false
Unique key using Symbol
const id = Symbol("userID")
Large calculation using BigInt
const total = 123456789123456789n * 2n
Each snippet represents something you'd actually build. A product listing, a cart, a login form. That's the real test of whether you understand a type. Can you use it, not just define it?
Also read: Node.js vs JavaScript: Key Differences and Benefits Explained
This one confuses almost everyone at first. Both null and undefined represent "nothing," but they mean different things.
Aspect |
Null |
Undefined |
| Meaning | Intentional absence of value | Value not yet assigned |
| Set by | Developer | JavaScript engine (by default) |
| Type | typeof null is "object" | typeof undefined is "undefined" |
| Common use | Resetting a variable, clearing an object | Uninitialized variables, missing function arguments |
let user = null // you decided there's no user
let age; // JavaScript hasn't assigned anything yet
console.log(age) // undefined
A quick note on that odd typeof null result. It returns "object" because of a bug from JavaScript's earliest days that never got fixed, since fixing it would've broken existing code across the web. It's not something you need to lose sleep over. Just remember it and move on.
Also read: JavaScript Hello World
Both are non-primitive types, but they solve different problems. Picking the wrong one makes your code harder to read and slower to work with.
Feature |
Array |
Object |
| Structure | Ordered list | Key-value pairs |
| Access | By index (arr[0]) | By key (obj.name) |
| Best for | Lists of similar items | Structured data with named fields |
| Example | ["a", "b", "c"] | { first: "a", second: "b" } |
When should you use each? If order matters and items are similar, like a list of product names, go with an array. If you're describing one thing with multiple properties, like a single user's name, email, and age, an object fits better.
Do read: Node JS Tutorial: Learn Node JS from Scratch
Even experienced developers slip up here sometimes. These are the mistakes that show up most often in real projects.
A quick checklist to avoid most of these:
None of this is complicated once you've seen it fail once. That's usually how it sticks.
Also read: DOM Model in JavaScript
If you're just starting out, don't try to memorize all seven primitive types plus three reference types in one sitting. Learn them in this order.
A common beginner misconception is thinking JavaScript has strict types like Java or C++. It doesn't. A variable can hold a number today and a string tomorrow.
let value = 10
value = "ten" // totally valid in JavaScript
This flexibility is powerful, but it's also why bugs related to types in JavaScript are so common. Stay alert to what a variable actually holds, not just what you expect it to hold.
Understanding types in JavaScript is one of the most valuable skills you can build as a beginner. Once you know how JavaScript stores values, distinguishes between primitive and reference types, and performs automatic type conversion, writing predictable code becomes much easier.
Start with the basics. Learn when to use strings, numbers, booleans, objects, and arrays before moving on to Symbol and BigInt. Practice with small examples, pay attention to how values behave during assignments and comparisons, and don't rely on assumptions. A solid grasp of JavaScript data types will help you avoid common bugs and prepare you for advanced topics like objects, asynchronous programming, and frameworks such as React or Node.js.
Ready to start your journey? Book a free consultation with upGrad today to find the best path for your career.
The types in JavaScript are divided into two categories. Primitive types include String, Number, Boolean, Undefined, Null, Symbol, and BigInt, while non-primitive types include Object, Array, and Function. Understanding both categories helps you choose the right type for different programming tasks and avoid common coding mistakes.
If you're wondering what are the data types available in JavaScript, the language provides seven primitive data types and one non-primitive category called Object. Arrays, functions, dates, and regular expressions are all specialized objects that help represent structured and reusable data within JavaScript applications.
JavaScript has seven primitive data types: String, Number, Boolean, Undefined, Null, Symbol, and BigInt. These values are immutable and stored directly in variables, making them independent when copied. Everything else in JavaScript belongs to the non-primitive Object category.
JavaScript uses the Number type for integers and decimal values. When calculations involve integers larger than the safe limit supported by Number, what is BigInt in JavaScript becomes relevant. BigInt stores very large integers accurately without losing precision, making it useful for financial and scientific applications.
If you're learning what is symbol data type in JavaScript, think of it as a way to create unique identifiers. Every Symbol is guaranteed to be unique, even if it has the same description as another Symbol. Developers commonly use Symbols as object property keys to prevent accidental naming conflicts.
JavaScript is dynamically typed, which means variables aren't permanently linked to one data type. A variable can store a number, then later hold a string or an object without requiring a new declaration. JavaScript automatically determines the type based on the value assigned at runtime.
Yes. Functions are special kinds of objects in JavaScript because they can be assigned to variables, passed as arguments, returned from other functions, and store their own properties. This flexibility makes functions a core building block for creating reusable and modular applications.
Besides plain objects, JavaScript includes several built-in object types such as Date, RegExp, Map, Set, Error, and Math. These objects provide ready-made functionality for handling dates, pattern matching, collections, mathematical operations, and error management without writing everything from scratch.
The way JavaScript stores values depends on their type. Primitive values are stored directly, while objects, arrays, and functions store references to locations in memory. This difference affects how variables are copied, compared, and modified, especially when working with shared objects in larger applications.
Use an object when you want to store related information using descriptive property names, such as a user profile or product details. Arrays are better for ordered collections like lists, search results, or shopping carts where items are accessed by their position rather than a key.
Start by understanding what are the data types in JavaScript that you'll use most often: String, Number, Boolean, Null, Undefined, Object, and Array. Once you're comfortable with these fundamentals, move on to Symbol and BigInt, which are designed for more specialized programming scenarios.
634 articles published
Sriram K is a Senior SEO Executive with a B.Tech in Information Technology from Dr. M.G.R. Educational and Research Institute, Chennai. With over a decade of experience in digital marketing, he specia...
Speak with Data Science Expert
By submitting, I accept the T&C and
Privacy Policy
Start Your Career in Data Science Today
Top Resources