JavaScriptBasics
JavaScript Data Types
Learn JavaScript data types, including primitive and non-primitive types, understand how data is stored, and see real-world examples used in modern JavaScript applications.
What are Data Types in JavaScript?Link to this section
Data types define the type of data a variable can hold. JavaScript is a dynamically typed language, which means you do not need to explicitly specify the data type of a variable—the JavaScript engine determines it automatically at runtime.
Understanding data types is essential because different operations behave differently depending on the type of data being used.
Categories of JavaScript Data TypesngLink to this section
JavaScript data types are broadly divided into two categories:
- Primitive Data Types
- Non-Primitive (Reference) Data Types
Primitive Data TypesLink to this section
Primitive data types store single, simple values and are immutable.
Number
The Number type is used to store both integers and floating-point values.note
JavaScript does not have separate types for integers and decimals—both are treated as Number.
String
The String type represents text and is enclosed within single quotes, double quotes, or backticks.tip
Use meaningful strings to improve readability and user experience in applications.
Boolean
Boolean represents logical values and can have only two values: true or false.Undefined
A variable that is declared but not assigned a value has the value undefined.note
Undefined usually indicates that a variable exists but has not been initialized yet.
Null
Null represents the intentional absence of a value.tip
Use null when you want to explicitly clear or reset a variable’s value.
Symbol
Symbol is a unique and immutable data type introduced in ES6, often used for unique identifiers.BigInt
BigInt is used to store very large integers that exceed the Number limit.warning
BigInt cannot be mixed directly with Number values in calculations.
Non-Primitive (Reference) Data TypesLink to this section
Non-primitive data types can store collections of values and are mutable.
Object
Objects store data in key-value pairs.Array
Arrays are used to store multiple values in a single variable.Function
Functions are reusable blocks of code and are also treated as data types in JavaScript.Checking Data Types Using typeofLink to this section
JavaScript provides the typeof operator to check the data type of a variable.
warning
<b>typeof null </b>returns <b> "object", </b>which is a known JavaScript quirk.
Why Understanding Data Types is ImportantLink to this section
tip
Strong understanding of data types makes learning advanced JavaScript much easier.
Check Your Understanding
Question 1 of 5JavaScript is a dynamically typed language.
Identify the Type
Declare variables of type Number, String, Boolean, and Null, then identify their types using typeof....
Fix the Bug
Why does the following code behave unexpectedly?...
typeof null;Create an Object
Create an object to store details of a course including title, duration, and price....
Array Practice
Create an array of your favorite programming languages and access the second element....