JavaScript Debugging


JavaScript Debugging

Programmers might face some syntax errors, they are not easy to discover. Many of them show nothing at the consol and you will never where the errors lays in your code

Searching for (and fixing) errors in programming code is called code debugging.

 

The console.log() Method

If your browser supports debugging, you can use console.log() to display JavaScript values in the debugger window. An error will show colored red and it will help you track your code and fix errors faster.

ME

 

Understanding the scope and the order of execution

Its important to understand the sequence of actions when you run a certain code. like the order and the scope. of course codes will run in turn, depends on its location within the js file, when you take into consideration this rule, it may be easier for you to discover the errors. the scope is important as well, the variable inside function cant be used outside the function but the opposite is false

 

The debugger Keyword

The debugger keyword stops the execution of JavaScript, and calls (if available) the debugging function. This has the same function as setting a breakpoint in the debugger. If no debugging is available, the debugger statement has no effect. With the debugger turned on, this code will stop executing before it executes the third line.

 

Errors

There many type of errors that could appear on the console, lets describe some of them:

  1. Syntax Error: Syntax has not been followed.
  2. ReferenceError: Tried to reference a variable that is not declared/within scope.
  3. TypeError: An unexpected data type that cannot be coerced.
  4. Range Error: Numbers not in acceptable range.
  5. NaN: not a number.

 

Its good to mention that some errors will not be shown on the console. so you need to focus and apply your experience and knowledge when trying to track the error, you can console.log in different parts of your code to see the outcome and you can go to google anytime you find yourself in a corner.


   

Get back to EMAM’S HOMEPAGE

I have created this page as a part of my project using Github, Please visit my profile, I will be more than happy to hear from you all.                       © Emam Shararah 2021