In the previous tutorial, you learned how to create variables using var, let, and const. Now let’s understand exactly what kind of values you can store inside them — this is where JavaScript Data Types come in.
What are Data Types?
A data type tells JavaScript what kind of value is stored in a variable — is it text, a number, true/false, or something more complex like a list? Knowing the right JavaScript Data Types helps you avoid bugs and write correct code.
let name = "Ali"; // text
let age = 25; // number
let isStudent = true; // true/false
JavaScript Data Types: Primitive Types
JavaScript has a few basic (primitive) data types that hold a single value.
1. String (text)
let city = "Karachi";
let message = 'Hello World';
console.log(city, message);
Strings are always written inside quotes — single (‘ ‘), double (” “), or backticks (` `).
2. Number
let age = 25;
let price = 99.99;
let temperature = -5;
console.log(age, price, temperature);
JavaScript uses one Number type for both whole numbers and decimals — no separate “integer” or “float” like other languages.
3. Boolean (true/false)
let isLoggedIn = true;
let hasDiscount = false;
console.log(isLoggedIn, hasDiscount);
Booleans are used heavily in conditions — like checking if a user is logged in or not.
4. Undefined
let city;
console.log(city); // undefined
A variable that’s declared but not given a value is automatically undefined.
5. Null
let selectedProduct = null;
console.log(selectedProduct); // null
null means “intentionally empty” — you set it yourself to show there’s no value on purpose.
JavaScript Data Types: Non-Primitive (Reference) Types
6. Array (list of values)
let fruits = ["Apple", "Banana", "Mango"];
console.log(fruits[0]); // Apple
console.log(fruits.length); // 3
7. Object (key-value pairs)
let student = {
name: "Ayesha",
age: 22,
city: "Karachi"
};
console.log(student.name); // Ayesha
console.log(student.age); // 22
Arrays and Objects let you group related data together — you’ll use these two constantly in real projects.
Checking a Variable’s Data Type
Use the typeof operator to check any variable’s data type:
console.log(typeof "Ali"); // string
console.log(typeof 25); // number
console.log(typeof true); // boolean
console.log(typeof undefined); // undefined
console.log(typeof null); // object (a known JS quirk!)
console.log(typeof [1,2,3]); // object
console.log(typeof {name:"Ali"}); // object
Practical Example: Student Record
let studentName = "Bilal"; // String
let studentAge = 21; // Number
let isEnrolled = true; // Boolean
let subjects = ["Math", "Science", "English"]; // Array
let address = null; // Null (not provided yet)
console.log(studentName, studentAge, isEnrolled);
console.log(subjects);
console.log(typeof studentAge);
Quick Recap
- String, Number, and Boolean are the most common primitive types
- Undefined means no value assigned; Null means intentionally empty
- Array stores lists; Object stores key-value pairs
typeoftells you a variable’s current data type
That completes JavaScript Data Types — now you know exactly what kind of data your variables can hold.
Practice Exercise
- Create one variable for each data type: String, Number, Boolean, Array, Object
- Print each variable using console.log()
- Use
typeofto print the type of each variable
Bonus Challenge
Create an object called car with properties: brand (string), year (number), isElectric (boolean), and features (array of strings). Print the full object, then print just the brand and features separately.
What’s Next?
In the next tutorial, we’ll cover JavaScript Operators — where you’ll learn how to perform calculations and comparisons on the data types you just learned.
Missed the last tutorial? Go back to JavaScript Variables, or browse the full JavaScript Tutorial Series.

