In this article, we are going to learn how to debug a code in ES6. Debugging is the process of finding and resolving the problem or mistake in code due to which it doesn’t work as expected. Debugging is an important part of programming that helps programmers to fix the bugs in the code.
Checking an error in ES6:Before debugging an error we must know where the error occurred in the code, then you can go to resolve it. In es6 we can find the error in the console section of the web browser.
Below is the way to access the console:
Right Click on browser -> Select Inspect -> Go to Console tab
Example: Basic example of error detection in the console in ES6.
HTML
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < meta http-equiv = "X-UA-Compatible" content = "IE=edge" > < meta name = "viewport" content = "width=device-width, initial-scale=1.0" > </ head > < body > < h2 id = "GFG" >Welcome To GFG</ h2 > < h3 >Error detection in Console in es6</ h3 > < script > function redirectME() { let age = 20 } console.log(age); </ script > </ body > </ html > |
Output:
Resolving errors in ES6
Using a Debugger: To Debug a code es6 provides a tool named debugger. A debugger allows the user to go at any line or function in the code to find and resolve the error.
Below is the way to access Debugger:
Right Click on browser -> Select Inspect -> Sources -> Go to your file
and debug code line by line using Debugger
Example:
HTML
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < meta http-equiv = "X-UA-Compatible" content = "IE=edge" > < meta name = "viewport" content = "width=device-width, initial-scale=1.0" > </ head > < body > < h2 id = "GFG" >Welcome To GFG</ h2 > < h3 >Error detection in Console in es6</ h3 > < script > function redirectME() { let age = 20; } console.log(age); </ script > </ body > </ html > |
Output:
Using JavaScript Validation parser or Validator for debugging: JavaScript Validation parser or Validators are the already written programs that check whether the valid syntax and rules of the language are used or not to write the code. Douglas Crockford’s JavaScript Lint is a JavaScript validator that is mainly used by developers.