Programming code can contain syntax errors or logical errors, many of which can be difficult to diagnose.
Sometimes, when errors occur, nothing happens—no error messages are displayed, and there are no clear indications of where to look.
The process of finding and fixing these errors in the code is called debugging.
Debugging can be challenging, but fortunately, modern browsers come with built-in JavaScript debuggers.
These debuggers can be toggled on or off, ensuring errors are reported to the user.
With a debugger, you can set breakpoints (specific points where the code execution pauses) and inspect variables as the code runs.
Typically, you can activate the debugger in your browser by pressing the F12 key and selecting “Console” from the debugger menu. (If this doesn’t work, follow the steps at the bottom of the page.)
If your browser supports debugging, you can use console.log()
to output JavaScript values in the debugger window.
<!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <script> a = 5; b = 6; c = a + b; console.log(c); </script> </body> </html> |