When you are writing JavaScript, do not expect to write it perfectly the first time.
To find the source of an error, it helps to know how scripts are processed.
Every statement in a script lives in one of three execution contexts:
GLOBAL CONTEXT (There is only one global context in any page.)
FUNCTION CONTEXT (Each function has its own function context.)
EVAL CONTEXT (NOT SHOWN)
A stack is a data structure that holds a list of elements.

PREPARE
EXECUTE
scope in JavaScript refers to the current context of code, which determines the accessibility of variables to JavaScript.

If a JavaScript statement generates an error, then it throws an exception. At that point, the interpreter stops and looks for exception-handling code.
Error objects can help you find where your mistakes are and browsers have tools to help you read them.
When an Error object is created, it will contain the following properties:
name(Type of execution)
message(Description)
file Number(Name of the JavaScript file)
line Number
Line number of error
There are seven types of built-in error objects in JavaScript.
Debugging is about deduction: eliminating potential causes of an error.