You may have only used console.log()
in JavaScript, but you can do many more things with the console object.
console.table()
If you have an object and want a clear view of it instead of having those ugly braces in the console you can use console.table()
const obj = {
name: "John",
age: 30,
city: "New York",
country: "USA",
}
console.table(obj)
console.error()
You will get a cool-looking (yeah 🙂) red color message for the instances where you want to make the stress on the bug more realistic.
console.error("Why is this rendering twice")
console.warn()
Similar to error but a little less stressful, you can mostly use this as a warning to yourself.
console.warn("Fix this in the next release!")
console.time()
You can get the computation time easily by using console.time()
, which starts the timer, and console.timeEnd()
which ends it to compute the time taken by your code.
You can pass a label inside the time()
function which makes the timer unique, so you can have as many number of timers in your program.
console.time("Time")
let count = 0
for (let i = 0; i < 100000; i++) {
count += 1
}
console.timeEnd("Time")
That's it for this blog... There are many more methods available, if you are interested you can check it out at MDN Docs.
Top comments (0)