What is console.log() for?
var time = new Date().getHours();
console.log("time: ", time);
var a = 10;
var b = 12;
var sum = a + b;
console.log("sum: ", sum);
console.log() is a function that can take many parameters (remember to always separate parameters with a comma). In the examples above I gave it two parameters:
- A string to identify the variable name I am checking
- The variable whose value I want to check
It is always helpful to see output in the console but it won't happen automatically if you don't have any errors. So, it is common to use console.log(yourVariableHere); to make sure everything is working as expected.
Then, when you are sure everything is working as expected, remember to get rid of any console.log() so it doesn’t clutter up your beautiful working code!