- What is the console used for?
The Console can be used to log information as part of the JavaScript development process, as well as allow you to interact with a web page by carrying out JavaScript expressions within the page’s context. Essentially, the Console provides you with the ability to write, manage, and monitor JavaScript on demand.
- How do you open the Console in Google Chrome?
To open the JavaScript Console in Chrome, you can navigate to the menu at the top-right of your browser window signified by three vertical dots in a row. From there, you can select More Tools then Developer Tools.
- What does console.log function do?
Rather than have pop-up alerts that we need to continue to click out of, we can work with JavaScript by logging it to the Console with console.log.
To print the Hello, World! string, we can type the following into the Console:
console.log(“Hello, World!”);
Copy
Within the console, you’ll receive the following output:
Output
Hello, World!
- How can you change the contents of an HTML page through the console?
You can then open up the Console and begin working with JavaScript to modify the page. We’ll begin by using JavaScript to insert a heading into the HTML.
let d = new Date();
document.body.innerHTML = "
Today’s date is " + d + “
”
Copy
You’ll receive the following output on the Console:
Output
“
Today’s date is Sat Jun 24 2017 12:16:14 GMT-0400 (EDT)
”