- alert interaction
- prompt interaction
- Developer tools (console)
Developer tools (console)
Why do we need console?
The console is a very useful tool to find an error in our code.
Browsers try to hide the error. This is because is not useful for a user to know that there is an error.
As programmers, we want to know where the error happened or what error we have, in order to fix it. This is where we need the console.
Copy and paste the code into your editor to see the output. Save the file in the folder "yourNameWEB2JS" as
example05.2.05.html". Next, open the file (
Ctrl+O) in your Chrome.
<title>Example of alert()</title>
Where can we find the console?
- Go to Chrome.
- Right click and chose “Inspect”. Chose the “Console” box. You are now in the console.
What do you see in the browser?
- Nothing. The browser hides the errors.
- Use the console in the developer tools to find the error.
- What is the error?
.Notice that the console shows the file and the line where the error appears!
Uncaught SyntaxError: missing ) after argument list
- Fix the error in order for the code to work properly.
The console is an amazingly useful tool and you can do various operations with it.
For example, go to the console and write 5+5 or alert(“Hi”) and hit enter. What do you see?