When I develop in the web, there are plenty of times that I want to see information about where I am in the program or what is going on in the Javascript when I load the page. I use the Console to watch updates but it can be difficult to read when you have possibly hundreds of log statements.
Usually you can just use the standard console.log function:
> console.log("Some information");
Some information
or
> console.debug("Some information");
Some information
or
> console.info("Some information");
Some information
You also get the line number and file that the output comes from in the console.
But did you know that you can use the following:
console.clear()
console.error(object)
console.table(array)
console.warn()
Let’s say you want to clear the current console. You can place in your code, or use it within the console itself.
console.clear();
Or you can get color coded lines with the warn or error functions:
> console.warn("This is a warning");
► This is a warning
> console.error("Error: Danger");
► Error: Danger
And if you need to display an array that and want a better layout use console.table():
> console.table(['a','b','c']);
(index) |
Value |
0 |
“a” |
1 |
“b” |
2 |
“c” |
► Array(3)