JavaScript Interpreted or Compiled? The Debate is Over.

Co-Founder, @CreoWis | Teacher, @tapaScript | Founder, @ReactPlay | YouTuber | Writer | Human
Search for a command to run...

Co-Founder, @CreoWis | Teacher, @tapaScript | Founder, @ReactPlay | YouTuber | Writer | Human
I've never come across someone who explains programming in such a concise and digestible manner. This was a great read.
The gist of your argument (IMO) is that because JS follows "some" similar processes of a compiler (tokenizing, specifically) that it is in fact, compiled. The problem with this argument, as j stated, is that all languages would fall into this and that's not correct.
When anything is actually compiled, it's expected to act and operate identically on all hardware and os's it's compiled for. If I write an iOS app in Swift and it's compiled for iOS, I can expect that app to work exactly the same on any platform that can run an iOS app (obviously, different versions of iOS may produce different results but that's getting off topic)
VS Chrome has a Javascript engine, Safari has a Javascript engine, Firefox has a .... Javascript engine. And while some of these browsers may use the same engine as a base, this is also why "sometimes" things work fine in Chrome and IE and sometimes they don't. They are all processing the JS as it comes in and "interpreting" it as they're designed to do so.
In a compiled JS app - they wouldn't. The code would be executed and the result is the result every time.
Another point, going further down this rabbit hole - a compiled language usually means the OS or the machine itself is executing the code directly. If JS was compiled, there would be no reason for the browser to execute and interpret the code. Now you could say Chrome is the "os" in this case and Chrome is executing the compiled code but IMO that's a stretch. There is still an engine looping through and interpreting the code. iOS, MacOS, Windows, Linux, et all are not interpreting compiled code - they're simply executing it.
Another point, going further down this rabbit hole - a compiled language usually means the OS or the machine itself is executing the code directly.
java is compiled, c# is compiled both are not running natively. Although the new javac coming up will allow native AOT compilation.
In a compiled JS app - they wouldn't. The code would be executed and the result is the result every time.
that's a tricky one. it depends on the linking process. If I use dynamic linking (.dll, .so) I actually use foreign ABIs in my compiled code so they could fail from system to system. at least in C, C++, Rust I got those problems I cannot talk about the other ones.
Also it would depend on the compile target that's the main reason why the VM exists so the translation between Highlevel and lowlevel isn't that complicated. Usually it's Highlevel -> stackmachine / VM -> asm target -> machine language
before I was writing my own compiler I would've taken a similar stance to be fair. It really gets tricky and hard to answer esp since JIT which basically takes the compiled code (VM/Interpreter -> fun fact Java starts 'somewhat interpreted' usually), creates statistical data about it and changes the execution layout and compiles 'more and more, based on the behaviour'
Still compiled as you actually mentions would mean that the VM code is 'listed' (compilare). But even here we could argue.
I don't wanna bore you further. it is just really tricky and it's like quantum physics and chemistry at which point do they merge? I really prefer pointing at the 'preprocessing' shit since a jvm always starts with the VM code and js just 'can' start with the VM code (caching).
that's the core difference and actually the 'interpreter' debate is off because we're actually debating 'script' vs 'compiled' to some degree.
anyhow ... bla
based on this definition php, python, perl are also compiled languages. actually every language that has a VM is compiled.
I know the definition changed over the years, but the reason those languages are not considered 'compiled' is the preprocessing/optimization step not the transformation itself. But ofc we could argue esp since graal in Java now supports compiled javascript to java-vm code and other things.
also since ES6 gets 'transpiled' it gets fuzzy quick. still it remains an interpreted language with JIT qualities to me.
Thanks j, never believed that, the debate is really over, ever 😄. About Js being compiled even with the qualities of the parsed language ..I have taken the answer is closer to Yes than No.
Thank you for reading through and Commenting, Appreciate!
I have taken the answer is closer to Yes than No
not really, the translation into the VM is a common step. js does JIT compilation though. and it's translated and executed on the fly. so ... nah ... or every modern interpreter language that does not basically just use eval is a compiled language.
Also there are no real optimizations or compile checks done in the compilation .... they are runtime checks mainly.
To me it's not closer to a compiled language than any other language with a VM. also it's a lot about NFA to DFA transformations which also don't really happen. There are a lot of subtle differences from the perspective of someone building a compiler.
But maybe it's just because I am building a compiler at the moment that I am so picky about this statement.
j No problem at all.. Glad to have this healthy discussion and hoping others will benefit too.
BTW.. All the best for your Compiler Development project. 👍
In this series, I'll bring some fundamental concepts from JavaScript to you. It is going to be fun learning for JS Beginners(and for Experienced folks too) to get the foundation right.
Introduction Execution Context is the most fundamental part of JavaScript programming language. In this post, we will take an in-depth dive into this concept to find out and it is not only fundamental but straightforward to understand. In many cases...
Traditional SSR is great, but it has a massive buffering problem. Let's look into the SSR Streaming and learn how it could be a game changer.

Learn how to build maintainable, reusable forms in React using design patterns like custom hooks, compound components, and context for scalable CRUD

Learn how JavaScript variables work, including let vs const, primitive and reference types, pass by value, and how JavaScript stores data in memory.

A beginner-friendly introduction to JavaScript covering what it is, how it works, and how to set up your JavaScript environment

Learn how the promises are handled internally using event loop. This concept is essentials to debug and work with async programming.

GreenRoots Blog - A Blog by Tapas Adhikary
186 posts
Educator | YouTuber | Building ReactPlay | Let's Connect
As a beginner to the JavaScript programming language, I had faced this question so many times:
Does JavaScript Interprets the Source code, or it really Compiles?
Many of the answers that I found on the internet made me as Confused as,
From https://giphy.com/
Few of the other online posts, discussions, blogs shed some bright lights on it. I thought it would be better to put it in a concise and easy to understand manner here.
This is the first post of the series, JavaScript: Cracking the Nuts. I hope you enjoy reading it.
In general, JavaScript is categorized as a dynamic or interpreted language. There are lots of misunderstandings about this fact. We need to ask and find the answers of,
As mentioned in Wikipedia,
An interpreter is a computer program that directly executes instructions written in a programming or scripting language without requiring them previously to have been compiled into a machine language program. It translates one Statement at a time.
Whereas,
A compiler is computer software that transforms computer code written in one programming language (the source language, like JavaScript, etc.) into another programming language (the target language, like machine code).
The first thing to understand, Computer doesn't understand the programming languages directly. Every programming language got its own syntax, grammar, and structure. No matter what programming languages(JavaScript, Python, Java, etc.) are writing the code with, it has to be translated into something that the machine(Computer) understands.
The most important fact here is, how does the JavaScript source code go through the journey of becoming a machine-understandable language? JavaScript Engine performs many of the steps(in fact, more cleaner and sophisticated ways) that a typical Compiler would perform in compiling source code.
In JavaScript, the source code typically goes through the following phases before it is executed,
Tokens. For example, the source code var age = 7; can be tokenize as, var, age, =, 7 and, ;."A Picture worth thousand words". Here is a pictorial representation of how these three phases take place:
JavaScript Code Compilation Steps
You can use the AST Explorer tool to see how code written by you gets parsed into an Abstract Syntax Tree(AST).
Created using AST Explorer
To conclude, JavaScript code indeed gets compiled. It is more closer to be Compiled than Interpreted. It is compiled every time. Next time, if someone asks the question, Does JavaScript really Compiles? The answer is a loud YES. After the compilation process produces a binary byte code, the JS virtual machine executes it.
Unlike other programming languages like Java, the compilation doesn't take place at the build time. The three phases described above are not the only things that happen to Compile JavaScript Source code. JavaScript engine needs to perform lots of optimization steps to tackle performance issues.
As a developer, we are abstracted away from all of these. We will see more in-depth topics about JavaScript Engine in the future post of the series.
It's time. Let's call it out, JS is a Compiled Language.
The resource I recommend for this subject is,
This is an excellent read if you are looking for more detailed explanations. You can start reading from this section directly. My favorite part from this read is,
So what do "parsed" languages have in common with "compiled" languages? First, all compiled languages are parsed. So a parsed language is quite a way down the road toward being compiled already. In classic compilation theory, the last remaining step after parsing is code generation: producing an executable form.
I hope you find the article useful. Please Like/Share so that it reaches others as well. If you enjoyed this article or found it helpful, let's connect. You can find me on Twitter(@tapasadhikary) sharing thoughts, tips, and code practices.
To get e-mail notifications on my latest posts, please subscribe to my blog by hitting the Subscribe button at the top of the page.
In the next post of the series, I'll be explaining another fundamental concept called, JavaScript Execution Context, like never before! Stay Tuned.