
Your JavaScript Array is a Hash Map in Disguise
TL;DR: JavaScript arrays are fundamentally objects where integer keys are treated as strings. To save performance, engines like V8 attempt to optimize these into contiguous memory blocks (Elements Kinds). However, mixing types or creating sparse "holes" triggers a de-optimization to Dictionary Mode, moving data from the 1ns CPU cache to 100ns RAM lookups. If you have ever wondered why typeof [] returns "object" , the answer isn't just "JavaScript is weird." It is an architectural warning. In the underlying C++ of the V8 engine, arrays are not fixed-size contiguous memory buffers by default. They are hash maps—specifically, exotic objects that map integer keys to values. While this makes JS incredibly flexible, it creates a massive performance hurdle that the engine has to work overtime to solve. Why does typeof return "object" for a JavaScript array? JavaScript arrays are keyed collections that inherit from the Object prototype, meaning they are essentially specialized objects where th
Continue reading on Dev.to Webdev
Opens in a new tab



