Skip to main content
JavaScript Data Types
Prepared By: Kale J. N.
Introduction
• What are Data Types?
– Define the type of data a variable can hold
– JavaScript is dynamically typed
Prepared By: Kale J. N.
Two Categories
• JavaScript data types are divided into:
– 1. Primitive Data Types
– 2. Non-Primitive (Reference) Data Types
Prepared By: Kale J. N.
Primitive Data Types
• - Immutable and hold single values
• Types include:
– String
– Number
– Boolean
– Undefined
– Null
– BigInt
– Symbol
Prepared By: Kale J. N.
String
• let name = "Sai";
– Textual data enclosed in quotes
– Example: "Hello", 'A', `Backtick`
Prepared By: Kale J. N.
Number
• let age = 25;
• let price = 99.99;
• Integers and floating-point
• Special values: Infinity, -Infinity, NaN
Prepared By: Kale J. N.
Boolean
• let isStudent = true;
• Only two values: true or false
• Used in conditions
Prepared By: Kale J. N.
Undefined and Null
• let x; // undefined
• let y = null; // null
• Undefined: declared but not assigned
• Null: explicitly no value
Prepared By: Kale J. N.
BigInt
• let big = 12345678901234567890n;
• BigInt: for very large integers
Prepared By: Kale J. N.
Non-Primitive Data Types
• Hold collections or complex entities
• Types:
– Object
– Array
– Function
Prepared By: Kale J. N.
Object Example
let person = {
name: "John",
age: 30
};
- Key-value pairs
- Mixed data types
Prepared By: Kale J. N.
Array Example
let fruits = ["Apple", "Banana", "Mango"];
- Ordered list
- Can store different types
Prepared By: Kale J. N.
Function Example
function greet() {
return "Hello";
}
Prepared By: Kale J. N.
typeof Operator
console.log(typeof "Hi"); // string
console.log(typeof 123); // number
- Used to check data types
Prepared By: Kale J. N.