completefrontend
Open lab My progress
THE JAVASCRIPT FIELD GUIDE

Reading error messages

Learn what JavaScript error names, messages, and stack traces are telling you so you can find bugs faster and search for help well.

By the end, you can
  • 01
    Name the kind of errorTell SyntaxError, ReferenceError, TypeError, RangeError, URIError, and EvalError apart, and say what each one means.
  • 02
    Read a stack traceStart at the line where the error happened, then follow the calls back to see how the code got there.
  • 03
    Search for helpPick the words from a message that everyone sees, search for them, then check the docs and your own code.

An error is a clue

Sometimes JavaScript reaches a line it cannot run. Then it stops and throws an error. That means it stops running your code and prints a report in the console, usually in red.

Red text can feel like "you failed". It is not. The report is a clue. It tells you what went wrong and where to look.

An error report has three parts:

  • The name, like TypeError or ReferenceError. It tells you the kind of mistake.
  • The message, like Cannot read properties of undefined. It tells you which step failed. The wording can differ from browser to browser.
  • The stack trace. It is a list of the functions that were running, newest first. The top one is where the error happened.
A console window showing one error in three parts. Part 1, the name: TypeError. Part 2, the message: Cannot read properties of undefined. Part 3, the stack trace: at applyDiscount, cart.js line 10.consoleTypeErrorCannot read properties of undefinedat applyDiscount (cart.js:10)1. name2. message3. stack trace
One error, three parts. The name says what kind of mistake it is. The message says what failed. The stack trace says where it happened. In a real console, the name and the message share the first line.
Real-life analogyAn error message is a warning light in a car

A warning light in a car does not fix the car. But it tells you where to look: the oil, the brakes, or the battery. The light's name tells you which part. A short note on the screen tells you a bit more. Then the mechanic follows the wire to the part that broke.

In real life: Which light is on, like the oil light
In JavaScript: The error name, like TypeError
In real life: The short note on the screen
In JavaScript: The error message
In real life: The mechanic follows the wire to the broken part
In JavaScript: You follow the stack trace to your code
Read an error in this order
  1. Read the error name and the message.
  2. In the stack trace, find the first line that points to your own file.
  3. Open that file at that line.
  4. Ask: "What value did this line expect, and what did it get?"

You have already used the console, and you saw strict mode turn quiet mistakes into errors. This lesson teaches you to read those errors. The next lesson, Debugging in the browser, shows how to pause your code and look inside it.

SyntaxError, ReferenceError & TypeError

INTERACTIVE

You will meet three errors all the time. Each one answers a different question:

  • SyntaxError: "Can JavaScript read this text?" Syntax means the grammar of the code, like brackets and commas.
  • ReferenceError: "Does this name exist?"
  • TypeError: "Can this value do this?"

A SyntaxError does not only come from your code file. JSON is a text format for data. It looks a lot like a JavaScript object. JSON.parse reads JSON text and turns it into a value. It reads the text while your program runs. So bad JSON text can throw a SyntaxError even after your code has started.

The table below has one row per error. Read each row as: "this name means this, and here is a tiny example."

The three most common JavaScript errors
Error nameWhat it meansA tiny example
SyntaxErrorJavaScript cannot read the text, because its grammar is wrong.JSON.parse("{bad json}") throws, because the JSON text is broken.
ReferenceErrorYour code uses a name, but no variable has that name.console.log(total) throws when no variable called total was made.
TypeErrorThe value exists, but it cannot do what the code asks.undefined.name throws, because undefined has no properties.

A missing property and a missing name are not the same thing. A property is a named value inside an object. An object can exist without a total property. Reading a property that isn't there gives undefined. It does not throw.

Reading a missing property gives undefinedPop out in the code editor (opens in a new tab)JavaScript
const cart = {};console.log(cart.total);

Line 1 makes an empty object called cart. Line 2 reads its total property. There is none, so it prints undefined. This can cause an error later. For example, cart.total.price would try to read price from undefined, and that throws a TypeError.

A missing name is different. If no variable has the name, JavaScript cannot look it up at all, and it throws. The next example uses try and catch:

  • JavaScript runs the code inside try.
  • If that code throws, JavaScript jumps to catch. The error is handed in as error.
  • error.name is the error's name, and error.message is its message.

A later lesson covers try and catch fully. Here they only let us print the error's name.

Using a name that was never made throws a ReferenceErrorPop out in the code editor (opens in a new tab)JavaScript
try {  console.log(total);} catch (error) {  console.log(error.name);}

Line 2 uses total, but no variable has that name. So JavaScript throws, and jumps to catch. Line 4 prints the error's name: ReferenceError. Remember the difference: cart.total is a missing property, and gives undefined. total on its own is a missing name, and throws.

Now a variable that exists, but holds a value that cannot do the job. Line 1 stores undefined in user. Line 2 tries to read the name property of that value. undefined has no properties, so JavaScript throws a TypeError. The exact message depends on your browser.

Reading a property of undefined throws a TypeErrorPop out in the code editor (opens in a new tab)JavaScript
const user = undefined;user.name;
Left: console.log(total). A name tag that says total points at nothing, because no variable called total exists. The result is a ReferenceError. Right: user.name. A box called user exists, but it holds the value undefined, which has no name. The result is a TypeError.console.log(total)totalnot foundReferenceErrorno such nameuser.nameundefineduserTypeErrorundefined has no name
On the left, JavaScript looks for a variable called total and finds none: a ReferenceError. On the right, the variable user exists, but the value inside it, undefined, has no name to read: a TypeError.

Try each error in the lab below. Each button runs a small piece of code in your browser. The lab uses try and catch so it can show you error.name and error.message.

Make each error happen in your browser
The code behind each buttonPop out in the code editor (opens in a new tab)JavaScript
const demos = {  reference() {    console.log(total);  },  type() {    const user = undefined;    return user.name;  },  range() {    return new Array(-1);  },  uri() {    return decodeURIComponent("%");  },  syntaxAtRuntime() {    return JSON.parse("{bad json}");  },  evalCompatibility() {    throw new EvalError("EvalError still exists");  },}; function inspectError(runDemo) {  try {    runDemo();  } catch (error) {    return {      name: error.name,      message: error.message,    };  }}
Your browser threwReferenceError
error.nameReferenceError
error.messagetotal is not defined

A ReferenceError means your code used a name, but no variable has that name. Here nothing is called `total`.

Ask next: Did I spell this name right, and did I make the variable?

Try it yourself

ReferenceError: total is not defined

Each button runs real code in your browser. The name is the same in every browser. The message can be worded differently, so read the one you get.

Look at what stays the same. The name is the same in every browser. The message can be worded differently. Chrome and Node say Cannot read properties of undefined (reading 'name'). Firefox says it a different way. When a lesson shows an exact message, it says which browser it comes from.

So in a catch block, use error.name to check the kind of error. Read error.message as a helpful note for people. Don't write code that checks for one exact message, because another browser may word it differently.

Check the error name, not the exact messagePop out in the code editor (opens in a new tab)JavaScript
try {  JSON.parse("{bad json}");} catch (error) {  console.log(error.name);  console.log(typeof error.message);}

Line 2 gives JSON.parse broken JSON text on purpose. It throws, and JavaScript jumps to catch. Line 4 prints SyntaxError. Line 5 uses typeof, which tells you what kind of value something is. It prints string, because the message is text. The example doesn't print the message itself, because its wording differs between browsers.

RangeError, URIError & EvalError

SORT

You will see the next three errors less often. Knowing them makes some scary messages easy to read.

One of them is about URIs. A URI is text that points to something, like a web address. Some characters can't go in a web address as they are, such as a space. So they are written as a code that starts with %. For example, a space is written %20. decodeURIComponent turns those codes back into normal text.

  • RangeError means a number is too big or too small for the job. new Array(-1) throws, because an array (a list of values) can't have a length below zero. (1).toFixed(101) throws too. toFixed rounds a number to a set count of decimal places, and that count must be from 0 to 100. In Chrome and Node the message says toFixed() digits argument must be between 0 and 100.
  • URIError means the % codes in the text are broken. % must be followed by a valid code. So decodeURIComponent("%") throws, with the message URI malformed. "Malformed" means "badly made".
  • EvalError is an old error. JavaScript today does not throw it on its own. It still exists so that old code keeps working. Your own code can still make one with new EvalError("message").

Got a RangeError or a URIError? Try the same function with an input you know is valid. If that works, the function is fine, and only your input is wrong.

Valid inputs work without errorsPop out in the code editor (opens in a new tab)JavaScript
console.log((12.5).toFixed(2));console.log(decodeURIComponent("tea%20and%20toast"));

Line 1 asks for two decimal places. That is between 0 and 100, so it prints 12.50. Line 2 turns each %20 back into a space and prints tea and toast. Valid inputs, so nothing throws.

Real-life analogyError names are like problems on a paper form

You hand a paper form to a clerk at a desk. When something is wrong, the clerk tells you what kind of problem it is. Each kind tells you what to fix: your handwriting, the box you used, what you wrote, or how big the number is.

In real life: The clerk can't read your handwriting
In JavaScript: SyntaxError: JavaScript can't read the grammar
In real life: You filled in a box the form doesn't have
In JavaScript: ReferenceError: no variable has that name
In real life: You wrote a word where a date should go
In JavaScript: TypeError: the value can't do this job
In real life: You wrote age 250
In JavaScript: RangeError: the number is outside the allowed range

Now sort some real messages by error name. Some messages come from built-in functions like JSON.parse, not from your own code's grammar. So always look at the line that threw, too.

Which error name goes with each message?
  • x is not defined
  • Cannot read properties of undefined (reading 'name')
  • Unexpected token
  • Invalid array length
  • Assignment to constant variable.
  • Unexpected end of JSON input
  • toFixed() digits argument must be between 0 and 100
Try it yourself
0 of 7 correct

Drag each message to the error name it usually comes with. If you are not sure, ask: what was the code trying to do?

Choose a category for every card. You can change an answer at any time; Reset clears them all.
URIError or SyntaxError?
  • URI malformed
  • URIError: malformed URI sequence
  • Unexpected token
  • Unexpected end of JSON input
Try it yourself
0 of 4 correct

Both errors come from reading text. Ask: is the text a web address with % codes, or is it JSON or code?

Choose a category for every card. You can change an answer at any time; Reset clears them all.

Reading a stack trace

STEP THROUGH

A stack trace is the list of function calls that were running when the error happened. It is printed under the message. The newest call is at the top. Each line of the list is called a frame.

  • The top frame answers: "Where did the error happen?"
  • Each frame below it answers: "Who called the one above?"

A frame usually gives a function name, a file name, and a place in that file: file:line:column. For example, cart.js:10:32 means file cart.js, line 10, character 32 on that line.

Four cards in a pile, newest on top: applyDiscount, calculateTotal, placeOrder, and the script. An arrow runs down the side, from newest to oldest. The top card is marked threw here. The bottom card is marked started here.newestoldestapplyDiscountcalculateTotalplaceOrderscriptthrew herestarted here
A stack trace lists the calls that were running, newest first. The top one is where the error was thrown. Each one below it is the call that called the one above. The bottom one is where it all started.
Real-life analogyA trail of breadcrumbs

You walk from room to room and drop a breadcrumb in each one. Then you trip. The crumb at your feet shows where you are now. The older crumbs show the way you came.

In real life: The newest crumb, at your feet
In JavaScript: The top frame: where the error happened
In real life: Older crumbs lead back to the start
In JavaScript: Lower frames: the calls that led there
In real life: Each crumb is in a known room
In JavaScript: Each frame gives file:line:column

Step through this small checkout bug. The order has a total, but no discount. Watch the "Running in" list grow as each function calls the next one.

Step through the calls that make a stack trace
Step 0 of 7Ready
Your turn: follow the blue line

Step through the calls. Watch the Running in list grow: script, then placeOrder, then calculateTotal, then applyDiscount.

Running in
  1. script
Next: line 13
function placeOrder(order) {  return calculateTotal(order);} function calculateTotal(order) {  return applyDiscount(order.total, order.discount);} function applyDiscount(total, discount) {  return total * (1 - discount.rate);} 
CallStoreChangeResultBlue line: runs next. Ran: already executed.
Recent returnsNothing yet. Start with the blue line.
A guided replay recorded from real JavaScript calls, not an engine debugger. Step follows executed statements; Back reviews a snapshot. Reset starts a fresh run.

Now see a real stack trace from your own browser. The error object keeps it as text in error.stack. Your browser may write it a bit differently. The steps stay the same: read the message, find the top frame in your code, then check the value that line used.

See a real stack trace from this browser
Checkout code with a missing discountPop out in the code editor (opens in a new tab)JavaScript
function placeOrder(order) {  return calculateTotal(order);} function calculateTotal(order) {  return applyDiscount(order.total, order.discount);} function applyDiscount(total, discount) {  return total * (1 - discount.rate);} placeOrder({ total: 40 });
Your stack tracenewest first
TypeError: Cannot read properties of undefined (reading 'rate')
    at applyDiscount (cart.js:10:32)
    at calculateTotal (cart.js:6:10)
    at placeOrder (cart.js:2:10)
    at cart.js:13:1
Try it yourself

Your browser may word it differently. Chrome and Node write each frame as at function (file:line:column). Firefox writes function@file:line:column.

The button runs the code on the left in a small hidden frame, kept apart from the rest of this page. So the function names match the lesson code.

Here is the same stack trace as Chrome and Node write it, with a note for each line. Chrome and Node both run JavaScript with the same engine, called V8. An engine is the part that runs your JavaScript. Firefox uses a different engine. It writes frames like applyDiscount@cart.js:10:32 instead.

A stack trace as Chrome and Node write ittext
TypeError: Cannot read properties of undefined (reading 'rate')    at applyDiscount (cart.js:10:32)    at calculateTotal (cart.js:6:10)    at placeOrder (cart.js:2:10)    at cart.js:13:1
  1. TypeError: Cannot read properties of undefined (reading 'rate') The error name and message. Start here.
  2. at applyDiscount (cart.js:10:32) Top frame: where the error happened.
  3. at calculateTotal (cart.js:6:10) Next frame: the function that called the one above.
  4. at placeOrder (cart.js:2:10) Keep reading down until you find your own code.
  5. at cart.js:13:1 The oldest call: the line that started it all.

Searching for answers

WORKFLOW

A web search can explain an error you have never seen. But the search works best with the right words. Error messages often contain your own names: your variables, your properties, your files. Nobody else uses those names. So keep the part of the message everyone sees, and leave out your own names.

Code that uses its own namesPop out in the code editor (opens in a new tab)JavaScript
const account = undefined;console.log(account.profile.name);

Line 1 stores undefined in account. Line 2 tries to read account.profile, so it throws a TypeError. In Chrome the message is Cannot read properties of undefined (reading 'profile'). The word profile is your own name. The rest is the same for everyone.

How to search for an error
  1. Copy the part of the message everyone sees: Cannot read properties of undefined.
  2. Put it in quotes, so the search looks for those exact words. Add the word JavaScript only if you get too many results about other things.
  3. Leave out your own names, like account and profile. Add them back only if the results are not helpful.
  4. Read MDN's page about JavaScript errors. Also read the docs for the function in the top frame of the stack trace.
  5. Make a small copy of the problem: the fewest lines of code that still throw the same error. Then explain each line out loud, as if to a friend. You will often spot the problem as you talk.

A good first search is "Cannot read properties of undefined", in quotes. Once you know what kind of error it is, go back to your code. Then ask the real question: "Why is this value undefined here?"

The message Cannot read properties of undefined, reading profile, split in two. Keep the shared part, Cannot read properties of undefined. Drop your own name, reading profile. The kept part goes into a search box, in quotes.Cannot read properties of undefined(reading 'profile')keepdropyour own namesearch"Cannot read properties of undefined"
Split the message in two. Keep the part every developer sees, and put it in quotes. Drop the part with your own names, like profile: other people's code uses different names.
Build a clean search from the name and the shared wordsPop out in the code editor (opens in a new tab)JavaScript
const errorName = "TypeError";const sharedMessage = "Cannot read properties of undefined";console.log(errorName + ' "' + sharedMessage + '"');

Line 1 stores the error name. Line 2 stores the part of the message everyone sees, without your own names. Line 3 joins them, with the message in quotes. It prints TypeError "Cannot read properties of undefined".

Make a minimal reproduction

SMALL STEPS

A minimal reproduction is the smallest piece of code that still shows the same error. "Minimal" means as small as possible. "Reproduction" means it makes the error happen again. With less code around it, it is easier to see which value is wrong.

To make one:

  1. Keep the line that fails, and the value it gets.
  2. Remove one part that seems unrelated.
  3. Run the code again.
  4. If the error is still there, repeat. If the error is gone, the part you removed mattered. Put it back and remove a different part.
A small copy of a profile card bugPop out in the code editor (opens in a new tab)JavaScript
function showProfileName(user) {  return user.name;} showProfileName(undefined);

Line 1 starts a function that expects a user object. Line 2 reads the user's name. Line 5 calls the function with undefined instead of a user. So line 2 tries to read name from undefined, and throws a TypeError. The rest of the web page is not needed to show this bug.

Now change only the value passed in. The function stays the same. Line 5 makes a user object. Line 6 calls the function and prints the name it returns: Asha.

Pass in a real user, and it worksPop out in the code editor (opens in a new tab)JavaScript
function showProfileName(user) {  return user.name;} const user = { name: "Asha" };console.log(showProfileName(user));

Sometimes a missing user is normal. For example, a visitor who has not logged in has no profile. Then your code should show something sensible, like the word Guest. But if the profile should always be there, don't hide the problem. Find out why it is missing, and fix the code that passes it in.

Show Guest when there is no userPop out in the code editor (opens in a new tab)JavaScript
function profileLabel(user) {  if (user === undefined || user === null) {    return "Guest";  }  return user.name;} console.log(profileLabel(undefined));console.log(profileLabel(null));console.log(profileLabel({ name: "Asha" }));

Line 1 starts a function. Line 2 checks for a missing user: is it undefined or null? (null is a value that means "nothing here, on purpose".) If so, line 3 returns Guest and the function stops. Line 5 reads the name only when a user is really there. The last three lines print Guest, Guest, and Asha, in that order.

There is a shorter way to write the same check, with two operators:

  • user?.name reads name only if user is not null or undefined. Otherwise it stops and gives undefined, without throwing.
  • a ?? b gives b when a is null or undefined. Otherwise it gives a.
The same check, written shorterPop out in the code editor (opens in a new tab)JavaScript
const user = undefined;console.log(user?.name ?? "Guest");

Line 1 has no user. On line 2, user?.name stops and gives undefined. Then ?? gives "Guest" instead, so it prints Guest. Don't use this to hide data that must be there, such as the total of an order. Find out why that value is missing instead.

The step-through below follows the same kind of bug through two functions. The top frame is where the error happens. Then move down the stack trace to find where undefined came from.

Follow a missing user back to where it came from
Step 0 of 5Ready
Your turn: follow the blue line

This step-through follows a missing user from the call on the page to the line that throws. It is a recording of the steps, not a live debugger.

Running in
  1. script
Next: line 9
function showProfileName(user) {  return user.name;} function renderProfile(user) {  return showProfileName(user);} 
CallStoreChangeResultBlue line: runs next. Ran: already executed.
Recent returnsNothing yet. Start with the blue line.
A guided replay recorded from real JavaScript calls, not an engine debugger. Step follows executed statements; Back reviews a snapshot. Reset starts a fresh run.

Where you’ll use this

You will read errors every day. A page does not load. A button does nothing. A test fails. Each time, these steps are usually the fastest way to the problem:

  1. Open the console. Find the first error that appeared after you clicked or loaded the page.
  2. Read the name and the message before you change any code.
  3. In the stack trace, find the first frame in your own file. Skip frames from browser add-ons or from code libraries you didn't write.
  4. Look at the values on that line. Is a name spelled wrong? Is a property missing? Is a number too big or too small?
  5. Still stuck? Search for the shared part of the message, and make a small copy of the problem.

The table below has one row per error name. Read each row as: "when I see this error, I ask this first, and the fix is often this."

What to check first for each error
When you seeAsk firstThe fix is often
ReferenceErrorDid I spell this name right, and did I make the variable?Fix the spelling, or make the variable where the code can see it.
TypeErrorWhat value is really here?Pass in the right value, or check for a missing value first.
SyntaxErrorIs my code's grammar wrong, or is it JSON text?Fix the code's grammar, or fix the broken JSON text.
RangeErrorWhich number is too big or too small?Check the number before you use it, or pass a number in the allowed range.

Common misconceptions

"The top frame of the stack trace always holds the real bug."

The top frame is where the error happened. But the cause can be earlier. A function lower in the stack may have passed in undefined, an empty string, or a wrong number.

"TypeError means I wrote the wrong type somewhere."

Plain JavaScript has no place to write types. A TypeError means a value, while the code ran, was asked to do something it cannot do.

"A SyntaxError always means my code file could not start."

Often it does. But some functions read text while your code runs, and they can throw a SyntaxError then. For example, JSON.parse("{bad json}").

"If my message is worded differently from a tutorial, it is a different bug."

Not always. Browsers word messages differently. Compare the error name and the step that failed first.

"It is best to search for the whole message."

Take out your own names first. Search the words everyone sees, in quotes. Add more details only if you need them.

Fun fact

The rules of JavaScript list the error names, like TypeError and RangeError. But they do not say what the English messages must say. That is why each browser can word them its own way.

Practice: read the error before fixing

6 EXERCISES
Exercise 1 · Warm-upPredict the error for a missing name

This code uses a name that no variable has. The catch block prints only the error's name, not the full message. Which name will it print? Decide before you run it.

Starter codePop out in the code editor (opens in a new tab)JavaScript
try {
  console.log(total);
} catch (error) {
  console.log(error.name);
}

Answer, then press Check. Spacing and letter case don’t matter.

    Exercise 2 · Warm-upPredict the error for a number that is too big

    The number exists, and the toFixed function exists. But the code asks for too many decimal places. The catch block prints the error's name. Which name will it print?

    Starter codePop out in the code editor (opens in a new tab)JavaScript
    try {
      (1).toFixed(101);
    } catch (error) {
      console.log(error.name);
    }

    Answer, then press Check. Spacing and letter case don’t matter.

      Exercise 3 · PracticeFind the function where the error happens

      This checkout code throws while it works out a discount. Picture its stack trace, newest call at the top. Which function holds the line where the error happens?

      Starter codePop out in the code editor (opens in a new tab)JavaScript
      function placeOrder(order) {
        return calculateTotal(order);
      }
      
      function calculateTotal(order) {
        return applyDiscount(order.total, order.discount);
      }
      
      function applyDiscount(total, discount) {
        return total * (1 - discount.rate);
      }
      
      placeOrder({ total: 40 });

      Answer, then press Check. Spacing and letter case don’t matter.

        Exercise 4 · PracticeFix a TypeError from a missing property

        The account object has no profile, so line 2 throws. Change line 1 so the account has a profile with the name Ada Lovelace. Don't change line 2. What does the fixed program print?

        Starter codePop out in the code editor (opens in a new tab)JavaScript
        const account = {};
        console.log(account.profile.name);

        Answer, then press Check. Spacing and letter case don’t matter.

          Exercise 5 · PracticeTurn a message into a search

          You see this error: TypeError: Cannot read properties of undefined (reading 'name'). Search results are more helpful when you search the words everyone sees, not your own names. Write what you would search for first.

          Answer, then press Check. Spacing and letter case don’t matter.

            Exercise 6 · ChallengeFix a profile card

            A profile card on a website breaks while it shows a person's name. Here is a small copy of the bug. Find the missing value. Then change the data, not the function, so the card prints Asha.

            Starter codePop out in the code editor (opens in a new tab)JavaScript
            function showProfileName(user) {
              return user.name;
            }
            const user = undefined;
            console.log(showProfileName(user));

            Answer, then press Check. Spacing and letter case don’t matter.

              Quiz: check your understanding

              7 QUESTIONS

              Some questions ask about ideas. Others show a small program and ask what it prints. Each answer explains why it is right or wrong.

              Lesson quiz · 7 questionsScore: first tries count
              1. Question 1 of 7What is the first thing to read in an error report?

                Choose an answer to see the explanation.

              2. Question 2 of 7No variable is called total. What does this code print?

                Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
                try {
                  console.log(total);
                } catch (error) {
                  console.log(error.name);
                }

                Choose an answer to see the explanation.

              3. Question 3 of 7user holds undefined. What does this code print?

                Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
                try {
                  const user = undefined;
                  console.log(user.name);
                } catch (error) {
                  console.log(error.name);
                }

                Choose an answer to see the explanation.

              4. Question 4 of 7The JSON text is broken. What does this code print?

                Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
                try {
                  JSON.parse("{bad json}");
                } catch (error) {
                  console.log(error.name);
                }

                Choose an answer to see the explanation.

              5. Question 5 of 7In a stack trace, where is the line where the error happened?

                Choose an answer to see the explanation.

              6. Question 6 of 7What is the best first search query for Cannot read properties of undefined (reading 'profile')?

                Choose an answer to see the explanation.

              7. Question 7 of 7Which sentence about EvalError is true?

                Choose an answer to see the explanation.

              Key takeaways

              • Read the error name first, then the message, then the stack trace.
              • SyntaxError: JavaScript can't read the grammar. ReferenceError: no variable has that name. TypeError: the value exists, but can't do what the code asks.
              • RangeError: a number is too big or too small for the job. URIError: the % codes in a web address are broken. EvalError: an old error that JavaScript no longer throws on its own.
              • A stack trace lists calls newest first. Find the first frame in your own code, and check the values on that line.
              • Search the words everyone sees, in quotes. Then read MDN, or the docs for the function in the top frame.

              One-line definition.
              An error message is JavaScript's report of what failed. A stack trace is the list of calls that led to it.

              Coming next: Debugging in the browser.

              Recap: a missing name, then a value with no propertiesJavaScript
              console.log(total);const user = undefined;user.name;
              CompleteFrontend Clear concepts. Working examples.