Javascript has several built-in data types that represent different values, which are classified into two categories: primitive data types and reference data types.
Primitive data types are immutable and it has 6 primitive data types such as number, string, boolean, undefined, null, and symbol.
Reference data types are mutable and it has 3 reference data types such as object, array, and function.
Primitive data types are immutable data types and stored directly in memory. They are accessed by value.
Represents numeric values. It can be integers or floating-point numbers.
let age = 35; let price = 69.99;
Represents sequences of characters and data enclosed within single (''), double (" "), or backticks (``) quotes.
let username = "Alice";
Represents a logical value, either true or false.
let isStudent = true;
Null: Represents the intentional absence of any object value.
Undefined: Represents a variable that has been declared but not assigned a value.
// undefined variable let undefinedValue; // undefined variable let undefinedVariable = undefined; // null value let nullValue = null;
Represents a unique identifier.
let uniqueID = Symbol("id");
Reference data types are mutable and stored as references to memory locations. They are accessed by reference.
It represents a collection of key-value pairs and is used for more complex data structures.
let person = { name: "Alice", age: 35, isStudent: false };
It represents a collection of elements, indexed by integers, starting from 0.
let marks = [55, 60, 77, 80, 99, 90]; // Accessing value of first element in `marks` array console.log(marks[0]) // Output: 55
it represents executable code that can be invoked.
const multiply = function(a, b) { return a * b; };