Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Javascript interpreted o compiled

18 views
Skip to first unread message

jseb...@gmail.com

unread,
Feb 21, 2017, 10:01:40 AM2/21/17
to mozilla...@lists.mozilla.org
Hi folks,

I have google it and I`m confused some say its interpreted

https://www.quora.com/Is-JavaScript-a-compiling-language-or-an-interpreted-language

some say it is compiled

http://stackoverflow.com/questions/15395347/does-a-browser-truly-read-javascript-line-by-line-or-does-it-make-multiple-passe

In the oficial documentation it states that there is a compile phase
https://developer.mozilla.org/en-US/docs/Glossary/Hoisting

but in the front page it says JS is interpreted
https://developer.mozilla.org/en-US/docs/Web/JavaScript

That is the true ?

Regards,
Sebastian

Jeremie Patonnier

unread,
Feb 21, 2017, 11:19:22 AM2/21/17
to jseb...@gmail.com, mozilla...@lists.mozilla.org
Hi Sebastian

To make it simple: fundamentally, JavaScript is interpreted. However,
JavaScript engine apply a set of optimizations that tend to make it looks
like JavaScript is a compiled language.

A JavaScript engine first parse a JavaScript file then interpreted it.
However, while it is interpreted there some cases than can be optimized:
for example, function that are called several times with a predictable
results can be transformed into some specific bitcode that that will be run
faster as it allows the JS engine to run it as if it where native binary
code (this is a bit over simplified but you get the idea) This is technique
is called Just In Time compilation (a.k.a JIT) as this compilation occured
on demand when it's necessary to have a faster executed code.

Modern JS engine also know a specific subset of JavaScript named ASM.js
this special way of writing JavaScript allow the engine to skip the
interpretation of JavaScript by turning immediately the JS code into an
executable bitcode. Again that looks very much like a compiled language.
This is so true that the best way to get some ASM.js JavaScript is to write
C++ code then transform it to ASM.js using transitional compiler tools
(LLVM + emscripten to be precise)

So as you can see it's a bit blurry but let's be clear: In essence,
JavaScript is an interpreted language. After that it's mostly JS engine
doing some voodoo magic to optimize that interpretation by using an
intermediate binary code representation with different optimization to get
such binary code as fast as possible.

Hope this help to understand
Best,
Jeremie
> _______________________________________________
> dev-mdc mailing list
> dev...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-mdc
> MDN contributor guide: http://bit.ly/ContributorGuide
>



--
Jeremie
.............................
Web : http://jeremie.patonnier.net
Twitter : @JeremiePat <http://twitter.com/JeremiePat>

Juan Sebastian Cruz Torrico

unread,
Feb 21, 2017, 12:16:03 PM2/21/17
to Jeremie Patonnier, mozilla...@lists.mozilla.org
Thanks for the clarification Jeremie !!

Saludos,
Sebastian Cruz

Eric Shepherd

unread,
Feb 27, 2017, 5:59:28 PM2/27/17
to Jeremie Pattonier, mozilla...@lists.mozilla.org, jseb...@gmail.com
I’ll add that it gets even fuzzier, since some of the very newest JavaScript engines actually do compile key parts of the code into native code. But that’s still a matter of an interpreter using optimization tricks, rather than a truly compiled language. A true compiled language is delivered to you already compiled and ready to run in native form.

> On Feb 21, 2017, at 11:18 AM, Jeremie Patonnier <jeremie....@gmail.com> wrote:
>
> So as you can see it's a bit blurry but let's be clear: In essence,
> JavaScript is an interpreted language. After that it's mostly JS engine
> doing some voodoo magic to optimize that interpretation by using an
> intermediate binary code representation with different optimization to get
> such binary code as fast as possible.


Eric Shepherd
Senior Technical Writer
Mozilla Developer Network <https://developer.mozilla.org/>
Blog: https://www.bitstampede.com/
Twitter: https://twitter.com/sheppy

0 new messages