Reading-notes

Error Handling & Debugging:

JavaScript can be hard to learn and everyone makes mistakes when writing it. This chapter will help you learn how to find the errors in your code. It will also teach you how to write scripts that deal with potential errors gracefully.

ORDER OF EXECUTION :

EXECUT.ION 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.

Every statement in a script lives in one of three execution contexts:

VARIABLE SCOPE The first two execution contexts correspond with the notion of scope:

The slack :

The javascript interpreter processes one line of code at time .

EXECUTION CONTEXT & HOISTING :

Each time a script enters a new execution context, there are two phases of activity:

UNDERSTANDING SCOPE :

UNDERSTANDING ERRORS :

ERROR OBJECTS :

Error objects can help you find where your mistakes are and browsers have tools to help you read them.

When there is an error, you can see all of this information in the JavaScript console I Error console of the browser.

ERROR OBJECTS CONTINUED :

Please note that these error messages are from the Chrome browser. Other browsers’ error messages may vary.

;

some common examples of the kinds of errors you are likely to see. As you can tell, the errors shown by the browsers can be rather cryptic.

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 :

A DEBUGGING WORKFLOW :

WHERE IS THE PROBLEM? WHAT EXACTLY IS THE PROBLEM?

BROWSER DEV TOOLS & JAVASCRIPT CONSOLE :

HOW TO LOOK AT ERRORS IN CHROME :

TYPING IN THE CONSOLE IN CHROME :

You can also just type code into the console and it will show you a result.

WRITING FROM THE SCRIPT TO THE CONSOLE :

WRITING TABULAR DATA :

objects

arrays that contain other objects or arrays.

BREAKPOINTS :

STEPPING THROUGH CODE :

CONDITIONAL BREAKPOINTS :

You can indicate that a breakpoint should be triggered only if a condition that you specify is met. The condition can use existing variables.

DEBUGGER KEYWORD :

HANDLING EXCEPTIONS :

If you know your code might fail, use try, catch, and finally.

Each one is given its own code block.

THROWING ERRORS:

DEBUGGING TIPS:

SUMMARY :