𝗛𝗼𝘄 𝗩𝟴 𝗠𝗮𝗸𝗲𝘀 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗙𝗮𝘀𝘁

JavaScript is dynamic. Types change. Objects change shape. This usually slows things down.

V8 makes it fast.

V8 uses JIT compilation. It does not compile everything at once. It runs code and watches it.

Two tools do the work:

V8 uses hidden classes. It treats objects like they have a fixed shape. This helps the CPU find data quickly.

It also uses inline caches. The engine remembers where a property lives. It does not look for it every time.

Problems happen when you change types. This is deoptimization.

V8 assumes a variable is a number. You change it to a string. V8 throws away the fast code. It goes back to the slow path.

You want your code to be predictable.

Predictable code runs faster.

Source: https://dev.to/bysontech_8dd1313811a8895/understanding-how-javascript-runs-in-the-browser-v8-rendering-engines-and-devtools-42oj