Reading a Stack Trace: the Traceback Upside Down
In this lesson, you read the error JavaScript prints when a script stops and found the mistake in it, starting from the top.
- A Python traceback puts the most recent call last, so you read it from the bottom. A JavaScript error puts it first, so you read it from the top.
- The first lines show the file and line number, the line itself with a caret, then the error’s name and message.
- Each
atline below is one call. The first is where the error was thrown, with a line and a column number. Each line under it is the caller of the one above. Anatline with no function name is the top level of the file, like Python’s<module>. - Stop reading where the frames start with
node:, such asnode:internal. They’re Node loading your module, not your code. - A
ReferenceErroris JavaScript’sNameError. Calling a method that doesn’t exist is aTypeError, where Python saysAttributeError. ASyntaxErrormeans JavaScript couldn’t read the file, so none of it ran.
The team’s check now keeps its report in a function. In JavaScript, function plays the role of
def, and braces hold the body where Python uses indentation. Functions get a course of their own later.
Here’s the port with one sys.platform left over from the Python: