-Order of Exscution :To find the source of an error, it helps to know how scripts are processed. The order in which statements are executed can be complex; some tasks cannot complete until another statement or function has been run.
-Execution Contexts :The JavaScript interpreter uses the concept of execution contexts. There is one global execution context; plus, each function creates a new new execution context. They correspond to variable scope.
- Global context: Code that is in the script, but not in a function. There is only one global context in any page.
- Function context : Code that is being run within a function. Each function has its own function context.
- Eval context (not shown) Text is executed like code in an internal function called eval().
-The Stack : The JavaScript interpreter processes one line of code at a time. When a statement needs data from another function, it stacks (or piles) the new function on top of the current task.
- The new scope is created.
- Variables, functions, and arguments are created.
- The value of the this keyword is determined.
- Now it can assign values to variables
- Reference functions and run their code
- Execute statements
-Understanding Scope: In the interpreter, each execution context has its own va ri ables object. It holds the variables, functions, and parameters available within it. Each execution context can also access its parent's v a ri ables object.
-Understanding Errors: 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: Error objects can help you find where your mistakes are and browsers have tools to help you read them.(look at page 466 in js.)
-Error objects Continued: look at page 467-468 in js.
-How to deal with errors: Now that you know what an error is and how the browser treats them, there are two things you can do with the errors.
- Debug the script to fix errors.
- Handle errors gracefully.