'Reference Error vs Syntax Error during JS compilation
I was doing a bit of research on interpreted v/s compiled. Found this article which states...
console.log("Hello World");
oops oops;
This code won't output Hello World because JS is compiled and because of oops oops; JS compiler will throw an error which it surely does. SyntaxError: Unexpected identifier
But if I remove the second oops i.e.
console.log("Hello World");
oops;
This code still throws an error, albeit a different error ReferenceError: oops is not defined, but it first writes Hello World to the console.
I understand both the errors. So, when there's a Syntax Error, the compilation process stops because it cannot process wrong syntax and cannot produce an AST (Abstract Syntax Tree) from what I understand. Hence, no byte code. But when it's a Reference Error, how can it compile?
Sorry if I'm asking this question on the wrong exchange. If so, just let me know the correct forum where I should be asking this question.
Also, I know it's unexpected behaviour, and I shouldn't be asking why broken code acts the way it does. I'm just curious.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
