- console.assert(expression, message)
- console.dir() and console.dirxml()
The console object gives you access to the browser’s console. It lets you output strings, arrays, and objects that help debug your code. The console is part of the window object, and is supplied by the Browser Object Model (BOM).
scirpt.js files to presents some of behavior of console object:
The purpose of the console.assert() function is ti test an expression is true or not. The console.assert() function is taking two parameters:
Assertion- this is an boolean expression. If assertion is true nothing happens on the console. If assertion is false, the error is thrown on the console.
ErrorMessage- the error message which is shown in the error state on the console. (error styled)
Below is an example of error message that is thrown in console:
The purpose of this function is to clear the console. Burt why you need to clear the console? Sometimes other libraries or frameworks can log many things on your console. For example this code should displayed many logs in console:
The only thing that we can do it is to add:
to the end of our code. This should clear console from the every logs. To clear console editor we can use:
CTRL + L.
Writes the number of times that count() has been invoked at the same line and with the same label.
After changing number of call of a function:
console.dir() and console.dirxml()
console.dirxml(object) this function is displaying the object in XML representation with all descendants. For example
console.dirxml() are identical. This two functions shows the same results.
console.error() method writes an error message to the console. Example of use:
Group functions are mainly making a group for other console functions with a title to create a block for debugging more clearly. This function allows to group objects into small blocks.
console.info() behave similar to
console.log() function but also shows an
i icon, an information icon next to the message and then shows the message.
This function displays arrays of object as a table.
This function displays a stack trace from the point where the method was called.
This is a deeper look into console object and some of the other methods. These methods are great tools to have available when we need to debug code.