Printing values and debugging
The console
object is non-standard; it is not part of the JavaScript language, but it is provided by the browser and Node.js. You can use it to print messages to the console, which is very useful for debugging purposes and for the purposes of this book, to follow along with the examples. It is quite common to use it to print the value of a variable. Take the following example:
const name = "Ulises"; console.log(name); // Ulises
Yes, you can use console.log
to print multiple values at the same time, separated by commas, and even include additional information to explain what you are printing. You don’t have to worry about the type of the variable as in other languages; console.log
will do it for you.
In some cases, you will need to help console.log
print the value of a variable; for example, if you want to print an object, sometimes you end up getting [object, object]
or similar as the output message. In this case, you will need...