It's time to ditch Medium for good! 🌈⚡️

Introducing Devblog by Hashnode. Blog on your domain for FREE. Highly customizable and optimized for developers.

Learn more

I am Mathias Bynens. Ask me anything.

RE:

Hi Mathias, What, according to you, should every beginner JavaScript programmer know about the V8 Engine?

Ideally, a beginning programmer knows absolutely nothing about any specific JavaScript engine. The number one thing to focus on is the JavaScript language. Read articles and books; follow interactive tutorials; start hacking on some hobby projects — whatever works best for you. But start with the language as a base, and keep an open mind. Learning about JavaScript engine internals as a beginning JS developer goes against that.

I’ll give you an example. V8 used to have a compilation pipeline called Crankshaft. For technical reasons, it didn’t do a great job of optimizing any code within try-catch blocks. This implementation detail caused some well-meaning developers to avoid try-catch altogether in their code “because otherwise it would be slow”, and instead work around the lack of proper error handling in complicated ways. Last year we shipped a new pipeline with TurboFan, our new optimizing compiler. try-catch can now be optimized in V8. All those hacky workarounds are now moot.

One can definitely gain valuable insights from studying a JavaScript engine. Heck, I’ve been doing this on a daily basis since last June :) But it’s important to recognize that optimizing for any specific engine doesn’t make much sense in the long-term. This applies to the Web platform with its diverse browser landscape, but to Node.js as well.

To optimize for performance across the board, i.e. in various JavaScript engines, learning about language details (e.g. by reading the spec) is far more valuable.

And there’s no reason you can’t do both! If you want to read about V8 internals while also learning something about JavaScript language details and getting performance tips that apply in all JS engines, check out my write-up on Elements Kinds, for example.

TL;DR Don’t jump through hoops trying to avoid a V8 implementation detail you once read about on Hacker News in 2011. Write idiomatic JavaScript code using modern language features. Focus on writing code that makes sense to you. That way, JavaScript engines across the board can focus on making it run fast for you.

Reply to this…

(24 questions) Take me to the AMA