Thursday, July 4, 2024
HomeLanguagesJavascriptHow to debug code in ES6 ?

How to debug code in ES6 ?

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.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Nango Kalahttps://www.kala.co.za
Experienced Support Engineer with a demonstrated history of working in the information technology and services industry. Skilled in Microsoft Excel, Customer Service, Microsoft Word, Technical Support, and Microsoft Office. Strong information technology professional with a Microsoft Certificate Solutions Expert (Privet Cloud) focused in Information Technology from Broadband Collage Of Technology.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments