Is Javascript Compiled or Interpreted?

ยท

1 min read

A piece of code tells the computer what to do when we run/execute the code. It generally has to be converted to machine-readable code to do so.

This can be done in two ways, Compilation and Interpretation.

When this conversion happens from top to bottom line by line it is called Interpretation. Every time the code runs it is Interpreted line by line.

Whereas sometimes this conversion is done ahead of time. when the code is run it actually is running the already converted computer instructions.

So languages can be both compiled and interpreted and sometimes languages like c++ can just be compiled which depends on the use case.

For Javascript people generally believe that it is Interpreted which is understandable as it is processed each time it is run but It's not entirely true. Javascript engine actually is pretty fast and compiles the code immediately before it is run so Javascript is compiled every time it is run unlike being compiled at the build time.

If you liked the article or have any suggestions for me please reach out on @aniketxparihar at Twitter! :)

Please read You Don't Know JS book Up and Going - chapter 1 for a more detailed explanation.

Thank You!