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;
let username = "Alice";
Represents sequences of characters and data enclosed within single (''), double (" "), or backticks (``) quotes.
let isStudent = true;
Represents a logical value, either true or false.
// undefined variable let undefinedValue; // undefined variable let undefinedVariable = undefined; // null value let nullValue = null;
let uniqueID = Symbol("id");
Null: Represents the intentional absence of any object value.
Undefined: Represents a variable that has been declared but not assigned a value.
Represents a unique identifier.
let person = { name: "Alice", age: 35, isStudent: false };
let marks = [55, 60, 77, 80, 99, 90]; // Accessing value of first element in `marks` array console.log(marks[0]) // Output: 55
const multiply = function(a, b) { return a * b; };
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.
It represents a collection of elements, indexed by integers, starting from 0.
it represents executable code that can be invoked.