console method
warn method
console.warn()
Method used to display warning in browser console It takes one parameter (warning text)
console.warn("This is a warning message");
error method
console.error()
Method allows us to print error messages in the console. It takes the error message as a parameter.
This method is often used for testing purposes.
console.error("This is a error message");
table method
console.table()
Method allows us to easily print objects and arrays in the form of tables within the console
console.table({
Name:"Alex", Age: 25});
assert method
console.assert()
Method allows us to print messages to the console based on conditions. It takes two parameters: if the first evaluates to false, the second parameter is printed.
console.assert(document.getElementById("btn"), "There is no element with ID btn");
dir method
console.dir()
Methods are used with objects. It identifies objects and prints them as an expandable list in the console
const person = {
name: 'John', age: 17, friends: ['Zulie', 'James', 'Alex']};
console.dir(person);
count and countReset methods
console.count()
Method allows counting the number of times count() has been called. The method is calculating itself
for (let i = 0; i <= 6; i++){
console.count();
}
If I call it again console.count()
, it returns the default value: 8 and so on
. On the other hand, we console.countReset()
reset the method counter to 0.
In our case the counter is now the number 8 and if we call console.countReset()
the method it will set the counter to 0