For engineers at the front end, console is no stranger to you, but how much can you know? Today let xiaopeng take a look at the world before big.
Chrome Console – Developer tools
Windows press F12, MAC press Command + Option + C or Command + Option + J to open the console
1. Output a message to the Web console
console.log('Hello world! ');
console.info('Hello world! ');
console.warn('Hello world! ');
console.error('Hello world! ');
console.debug('Hello world! ');
Copy the code
2. Console.dir () displays an object for all properties and methods
console.dir(document);
Copy the code
3. Console.table () displays the data as a table
This method takes a required parameter, data, which must be either an array or an object
var names = [
{
name: "Xiao Ming",
age: 20,
gender: 'male'
},
{
name: "Little red",
age: 18,
gender: 'woman'
},
{
name: "Xiao li",
age: 22,
gender: 'male'
}
]
console.table(names)
Copy the code
4. Calculate the time occupied by the operation
Note: Each timer must have a unique name
console.time('timer');
let count = 0;
for (let i=0; i<100; i++) {
count++;
}
console.timeEnd('timer');
Copy the code
5. Output the number of calls
Console.count () This function takes an optional argument label
let user = "";
function greate () {
console.count(user);
return 'hi' + user;
}
user = 'Bob'; // Lable is Bob Greate (); user ='John'; // Lable is John Greate (); greate(); console.count('John');
Copy the code
6. Determine whether the assertion is true
Console.assert () writes an error message to the console if the assertion is false, or true if the assertion is true. There is no response
console.assert(1==1, 'Success');
console.assert(1==2, 'Error');
Copy the code
Group 7.
Console.group () creates a group on the console until the group ends with a call to console.groupend ()
console.group('Today's Event');
console.log('eat');
console.log('sleep');
console.log('Beat the beans');
console.groupEnd();
console.group('Things for Tomorrow');
console.log('hanami');
console.log('moon');
console.log('Autumn fragrance');
console.groupEnd();
Copy the code