DEV Community

Discussion on: Is Javascript a compiled language?

Collapse
 
bgadrian profile image
Adrian B.G.

If you take it that literal ... yes ... but no.

It is so dynamic that it doesn't even compile a function until is called for the first time.

JS is compiled into machine code, but at run time, is exact the opposite of what people mean when they talk about "compiled languages". Also even if is technically not correct, most of the time we refer to JS compiler engines as "interpretors". It is correct if you consider the dynamic interpretation "eval", or when considering that you need a VM/engine to translate it at each run.

I think it is a good thing that you want to raise awareness about the technical details of what is happening to JS code when is executed, devs will write better code hopefully with this in mind.

PS: if you want to be that literal, you should not use the term JavaScript at all, it is ECMAScript.

Collapse
 
genta profile image
Fabio Russo

I forgot the fact that every block is compiled when called... as you said for the function.

I know that the idea of “compiling” is not fitting totally to It... but It’s there in many ways.

Collapse
 
bgadrian profile image
Adrian B.G. • Edited

Anyway, from what I know, all of these are just implementation details. I think ECMAScript doesn't specify if it should be interpreted, compiled or when each block should be compiled.

Bottom line, I agree that all devs should know more about how the compiler works, a lot of bad code is written under the "it is more optimal this way" umbrella, not knowing that the compiler will do that for him anyway, and they could have kept the code more human friendly.

Thread Thread
 
genta profile image
Fabio Russo

Agree.

JS is pretty easy at a first sight, but if you want to use It not just as the “browser languagae” you need to know grammar, lexing, values, coercion...
Non that It’s needed to know the specifications completely (they’re always online for you) but at least, one time, you should read It and have an idea on how It works.