Curriculum
Data Types in JavaScript are used to define the type of data stored inside variables. Understanding Data Types in JavaScript is essential for beginners because every JavaScript program works with different kinds of values such as numbers, text, boolean values, arrays, and objects. Learning data types helps developers write efficient, error-free, and dynamic JavaScript applications.
In JavaScript, every variable stores some kind of data. The type of stored data is called a data type.
JavaScript data types help the browser understand:
Example:
let name = "John";
Here:
"John" is a string data typeDifferent data types behave differently in JavaScript programs.
Data Types in JavaScript are important because they help:
Without data types, programming logic would become difficult to manage.
JavaScript data types are mainly divided into:
Primitive data types store single values, while non-primitive data types store collections of data.
Primitive data types are basic data types provided by JavaScript.
Main primitive data types:
The String data type stores text values.
Example:
let language = "JavaScript";
console.log(language);
Output:
JavaScript
Strings are written inside:
" "' 'Strings are commonly used for:
The Number data type stores numeric values.
Example:
let marks = 95;
console.log(marks);
Output:
95
JavaScript numbers include:
Examples:
1025.5Numbers are used in calculations and mathematical operations.
The Boolean data type stores only two values:
truefalseExample:
let isLoggedIn = true;
console.log(isLoggedIn);
Output:
true
Booleans are used in:
A variable without a value automatically becomes undefined.
Example:
let user;
console.log(user);
Output:
undefined
This means the variable exists but no value is assigned yet.
null represents an intentionally empty value.
Example:
let selectedUser = null;
console.log(selectedUser);
Output:
null
null is commonly used when developers want to clear variable values.
BigInt stores very large numbers beyond the normal JavaScript number limit.
Example:
let largeNumber = 12345678901234567890n;
console.log(largeNumber);
BigInt is useful in:
Symbol creates unique identifiers.
Example:
let id = Symbol("user");
console.log(id);
Symbols are mostly used in advanced JavaScript programming.
Non-primitive data types can store multiple values.
Main non-primitive types:
Arrays store multiple values in a single variable.
Example:
let colors = ["Red", "Blue", "Green"];
console.log(colors);
Arrays are useful for:
Objects store data in key-value format.
Example:
let student = {
name: "Rahul",
age: 22
};
console.log(student);
Objects are widely used in web applications and APIs.
JavaScript provides the typeof operator to check data types.
Example:
let city = "Jaipur";
console.log(typeof city);
Output:
string
This helps developers identify variable types during debugging.
Data Types in JavaScript are used in:
Every modern JavaScript application uses multiple data types.
Beginners often:
null and undefinedExample mistake:
let marks = "90";
This stores the number as a string instead of a numeric value.
Understanding Data Types in JavaScript helps developers:
Data types are one of the most important foundations of programming.
Data Types in JavaScript define the type of values stored in variables. JavaScript includes primitive data types like string, number, boolean, undefined, and null, along with non-primitive types like arrays and objects. Understanding data types is essential for writing efficient JavaScript programs and modern web applications.
Data types define the type of values stored inside JavaScript variables.
Primitive data types include string, number, boolean, undefined, null, BigInt, and symbol.
undefined means no value is assigned, while null represents an intentionally empty value.
The typeof operator checks the data type of a variable.
Data types help developers store, manage, and process data correctly.
WhatsApp us