Memory
Memory is the brain’s ability to encode, store, and retrieve information, allowing us to learn, adapt, and recall past experiences.
Types of Memory
Memory is categorized into two types:
Stack Memory (Primitive)
Used for storing fixed-size data like numbers, booleans, and references.
Heap Memory (Non-Primitive)
Used for storing dynamic data like objects, arrays, and functions.
Characteristics of Heap Memory:
- Dynamic Allocation: Memory is allocated and deallocated at runtime.
- Flexible Size: The size of the memory can grow and shrink as needed.
- Garbage Collection: JavaScript automatically manages memory allocation and deallocation through garbage collection.
Example:
let person = {
name: "John",
age: 30,
};
let numbers = [1, 2, 3, 4, 5];
function greet() {
console.log("Hello, World!");
}