0

I was trying to communicate with a coworker about a JavaScript error I was being notified about in my browser's console window when I realized that I wasn't sure if I should refer to this as a compiler error or a runtime error; especially if said error is only popping up when, let's say, a certain button is clicked. Then I'd suspect that such an event is specifically a runtime error, but I'm not sure.

Maybe this gets into semantics and there's no formal definition, so let me know and I'll take this post down.


EDIT

This is a wonderful post that gives some insight into if JS is compiled or interpreted:

Is JavaScript interpreted by design?

3 Answers 3

6

If by compiler error, you mean syntax errors, then yes they are. Console also throws runtime errors. For example, trying to perform some action on null/undefined property.

JavaScript is an interpreted language. Therefore, we cannot call them compiler errors but instead parsing errors.

Browser console shows us the following:

  • Syntax errors at the time script is loaded and parsed.
  • Runtime errors (access an undefined property of some object)
  • Other warning messages (a deprecated method or property warning)
  • Console messages(console.log(), console.warn(), console.error())
  • Error messages with stack trace (Error())
2

You're probably looking for "Syntax error". The linked Wikipedia article says about this:

For compiled languages syntax errors occur strictly at compile-time. A program will not compile until all syntax errors are corrected. For interpreted languages, however, not all syntax errors can be reliably detected until run-time, and it is not necessarily simple to differentiate a syntax error from a semantic error; many don't try at all.

0

Since JavaScript is a highly dynamic, interpreted scripting language, the term "compiler error" doesn't hold much meaning. I'd really only apply that term to an error generated in parsing--if something is syntactically invalid, that's definitely a compiling error. But beyond that, once something parses successfully, the interpreter essentially starts trying to interpret it, and with a very dynamic, weak typing system, it doesn't go through many of the correctness checks that are common in other languages before moving on to the interpretation, instead simply trying to find ways to muddle through at runtime, so pretty much anything after that should be considered a runtime error, even if it should have been a compile error in a stricter language.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.