View on GitHub

reading-notes

Hello, My name Emran Aloul, I'm a mechanical engineer, I like to technical work and to have the ability to build or create something, This page includes the reading summarization we have in the daily reading assignments for 102, and certain folder for the reading notes for 201

Error Handling and Debugging

ORDER OF EXECUTION

EXECUTION CONTEXTS

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

  1. 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.
  2. EVAL CONTEXT (NOT SHOWN) Text is executed like code in an internal function called eval {).
  3. GLOBAL SCOPE If a variable is declared outside a function, it can be used anywhere because it has global scope. If you do not use the var keyword when creating a variable, it is placed in global scope. FUNCTION-LEVEL SCOPE When a variable is declared within a function, it can only be used within that function. This is because it has function-level scope.

EXECUTION CONTEXT & HOISTING

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

  1. PREPARE
    • The new scope is created
    • Variables, functions, and arguments are created
    • The value of the this keyword is determined
  2. EXECUTE
    • Now it can assign values to variables
    • Reference functions and run their code
    • Execute statements

      Error Objects

    • 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: objects There are seven types of built-in error objects in JavaScript:

objects2

JavaScript Errors - Throw and Try to Catch

The try statement lets you test a block of code for errors.

The catch statement lets you handle the error.

The throw statement lets you create custom errors.

The finally statement lets you execute code, after try and catch, regardless of the result.

JavaScript try and catch

The try statement allows you to define a block of code to be tested for errors while it is being executed.

The catch statement allows you to define a block of code to be executed, if an error occurs in the try block.

JavaScript Throws Errors

When an error occurs, JavaScript will normally stop and generate an error message.

The technical term for this is: JavaScript will throw an exception (throw an error).

JavaScript will actually create an Error object with two properties: name and message.

The throw Statement

The throw statement allows you to create a custom error.

Technically you can throw an exception (throw an error).