Is JavaScript Interpreted or Compiled Language

Is JavaScript Interpreted or Compiled Language

People often say "JavaScript is a Interpreted language" or you might have heard "no no.. JavaScript is a compiled language". So many discussion and debates flows on the internet here and there.
Let's have a look on the facts weather it's a compiled language or it's interpreted language.

Assumption-1 JavaScript is a Compiled Language.

console.log("hello");
console.og("world");

As we have assumed JS is Compiled Language, compiler will go through each and every line of code and when all the code completes then it will start executing or if it detects error it will through the error.
In this case it detects there is "console.og" but it should be "console.log" then and there i will through the error. Hence there will be no log in the console except error.

Assumption-2 JavaScript is a Interpreted language

console.log("hello");
console..log("World");

Here we are assuming JS is Interpreted Language, interpreter will go through every line and execute it, and if it detects the error then it will through error and stops then and there.
so, in this case 'hello' should be printed and at line 2 error should be thrown.

Let's see what JS does in both scenario.

Assumption-1

when we run the code it's not working as we discussed above.
Here, it's consoling "hi" but it should not because we assumed it as compiled language.

Assumption-2

The same goes to this case it's also not working as we discussed above.
Here, it's consoling nothing except error. Being interpreted language it should print "hi".

So, by all the experiment done above it's seems javaScript is neither compiled nor interpreted.

Then what JavaScript is in actuality, it is a combination of both the process compilation and interpretation .

Boil down

JavaScript goes through two phases
1. Parsing Phase.
2. Execution Phase.
This is how javaScript works

FOR MORE REFER ECMASCRIPT