Hash Map
ELI5 — The Vibe Check
A hash map is a super-fast lookup table. You store a value under a key (like a label), and you can find it instantly without searching through everything. It is like a dictionary — you do not read every page to find 'apple', you jump straight to 'A'. In JavaScript, plain objects and the Map class are hash maps.
Real Talk
A hash map (also called hash table, dictionary, or map) is a data structure that maps keys to values using a hash function. The hash function converts a key into an array index, enabling average O(1) lookup, insertion, and deletion. Collisions (two keys with the same hash) are handled by chaining or open addressing. In JavaScript, plain objects and Map serve as hash maps.
Show Me The Code
// JavaScript Map (true hash map):
const cache = new Map();
cache.set('user:123', { name: 'Alice' }); // O(1) insert
const user = cache.get('user:123'); // O(1) lookup
cache.has('user:999'); // false
// Plain object as hash map:
const index = {};
index['alice@email.com'] = userId;
// Use case: counting word frequency
const freq = {};
for (const word of words) {
freq[word] = (freq[word] ?? 0) + 1;
}
When You'll Hear This
"Use a hash map to cache the results." / "A hash map gives you O(1) lookup instead of scanning the whole array."
Related Terms
Array
An array is a list of things in order, like a numbered row of boxes. Box 0 holds the first item, box 1 holds the second, and so on.
Big O
Big O notation is how we describe how fast (or slow) an algorithm gets as the input grows. O(1) means instant no matter the size.
Data Structure
A data structure is a way of organizing information in your code so it is easy to use and fast to access.
Object
An object is like a labeled container — instead of numbered boxes like an array, each box has a name.