Let's examine several methods to debug code. The first one is the JavaScript console.log() method:
- Create a new file, name it index.html, and write the following code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Debugging</title> </head> <body> <script> var num1 = 5; var num2 = 8; var sum = num1 + num2; console.log(sum); </script> </body> </html>
- After navigating to this web page, press the F12 key on the keyboard and click on the Console tab. You should see 13 as follows (the screenshot is taken from the Google Chrome browser, but it's almost identical in other browsers):
If we want to see a variable's ...