Tapas Adhikary
Educator @tapaScript | Founder CreoWis & ReactPlay - Writer - YouTuber - Open Source
Introduction 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, ...
blog.greenroots.info4 min 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.
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.
Ian Mugenya
Software Engineer
I've never come across someone who explains programming in such a concise and digestible manner. This was a great read.