Is JavaScript translated from source code to machine code with a JIT piler or an interpreter? Or does it depend on the browser and the JavaScript engine you are running?
Is JavaScript translated from source code to machine code with a JIT piler or an interpreter? Or does it depend on the browser and the JavaScript engine you are running?
Share Improve this question edited Apr 30, 2022 at 14:04 slasky 3,0764 gold badges30 silver badges40 bronze badges asked Jul 16, 2016 at 11:42 OversteOverste 1292 silver badges4 bronze badges 3- 2 en.wikipedia/wiki/JavaScript First sentence, with more information in the third paragraph. – str Commented Jul 16, 2016 at 11:50
- 1 Yes, sometimes. Yes. Yes. – Bergi Commented Oct 14, 2016 at 13:16
- You can go throw the answer: : softwareengineering.stackexchange./questions/138521/… – NITISH KUMAR Commented Apr 4, 2021 at 7:09
3 Answers
Reset to default 9Javascript is an interpreted language.It is directly interpreted by browsers for execution.
But,modern browsers support JIT pilation which converts it to bytecodes for high performance.
JavaScript is scripting language and browser is executing scripts which are in text format. So by definition that makes JavaScript interpreted language.
Compiled languages are those which are executed from binary files.
JIT pilation is just something that JavaScript engines can do as way of optimization, but you never truly generate binary JS files, so language is interpreted one.
Javscript is nowadays a mix of interpreter and piled language; this is called JIT pilation:
When you write the code, the JS engine tokenizes the code and converts it to AST (a tree-like structure), then it goes to the profiler. The profiler's main work is to check for code that runs repetitively like a loop or a function that is called many times, and take that part of the code and throw it to the TurboFan piler. TurboFan's main job is to optimize and pile that portion of code into an optimized binary and then run it. There are other parts of the code that are interpreted by the Ignition piler which converts the code into bytecode and runs it.