These bugs usually trigger something painfully obvious and JavaScript will help you with them.
In the code above, in the console, there is some red text screaming at us saying: ReferenceError: oops is not defined
and under that, it tells us it happened in index.js:2:7
(the main JavaScript file, line 2, column 7).
Underneath is what is called a stack trace. The “stack” is how JavaScript and other coding languages know which function you’re currently in. Say, if you had a function called oopsie
call another function called daisy
, they would all show up in the stack trace.
Notice how the stack trace, now shows us the error happened in daisy
at line 7, which was called oopsie
at line 3, which was called in the program at line 10.
This is how you can get an understanding of the conditions and places where an error could’ve happened.