JavaScript Console Tricks
JavaScript Console Tricks
JavaScript Console Tricks
BREAKING
Home
JavaScript - Generators...
Javascript Rust
5:02
Privacy
Home Javascript
Popular Posts
JavaScript Console
Tricks
by Shubham Guleria - December 14, 2022 0 RUST
Multithreading in Rust
by Shubham Guleria - December 12, 2022
The problem
https://www.thealphadev.com/2022/12/javascript-console-tricks.html?utm_source=reactdigest&utm_medium&utm_campaign=1492 1/8
23/1/23, 9:23 JavaScript Console Tricks
console.table
Facebook
With the help of this technique, you can produce tabular
data in a clear and comprehensible manner. Console.table The Alpha Dev
will display the data in a tabular style, which is simpler to 11 followers
console.group
console.group and console.groupEnd. These methods allow
you to create a nested, collapsible group in the console.
Main Tags
This can be useful for organizing and structuring your
Javascript (9) MySQL (2) React (4)
debug output, so you can easily see what's happening at
different levels of your code. React Native (3) Rust (9)
https://www.thealphadev.com/2022/12/javascript-console-tricks.html?utm_source=reactdigest&utm_medium&utm_campaign=1492 2/8
23/1/23, 9:23 JavaScript Console Tricks
console.time
console.time and console.timeEnd. These techniques let you
calculate how long it takes a block of code to run. This
Search This Blog
might help you locate and optimize performance
bottlenecks in your code.
Search Ok
console.time('Fetching data');
fetch('https://reqres.in/api/users')
.then(response => response.json())
.then(data => {
console.timeEnd('Fetching data');
// Process the data
});
console.assert
With the help of this technique, you may add statements to Jan (2)
function add(a, b) {
return a + b;
}
// Test the add function
const result = add(2, 3);
https://www.thealphadev.com/2022/12/javascript-console-tricks.html?utm_source=reactdigest&utm_medium&utm_campaign=1492 3/8
23/1/23, 9:23 JavaScript Console Tricks
console.assert(result === 5, 'Expected
Home
2 + 3 Javascript
= 5'); Rust
About Me
console.log('%cHello world!', 'color:
Shubham Guleria
red; font-weight: bold;'); Show more
Using the chosen CSS style, this will produce the words
"Hello world!" in bold and red.
console.trace
Create a stack trace by using the console.trace method. This
can help you understand how your code is being executed,
as well as pinpoint the source of a specific log message.
console.dir
https://www.thealphadev.com/2022/12/javascript-console-tricks.html?utm_source=reactdigest&utm_medium&utm_campaign=1492 4/8
23/1/23, 9:23 JavaScript Console Tricks
5:02
const obj = {
id: 1,
name: 'John Doe',
address: {
street: '123 Main St',
city: 'New York',
zip: 10001
}
};
console.dir(obj);
console.count
To get the number of times a certain log message has been
output, use the console.count method. This can be helpful
for tracking the frequency with which a specific code path
is executed and for locating trouble spots in your code.
function foo(x) {
console.count(x);
}
foo('hello');
foo('world');
foo('hello');
In the console, this will print the word "hello" and the
number 1. The word "world" will then be produced in the
console, followed by the number 1. The string "hello" will
be output once more before being followed by the number
2. (since it has been called twice).
console.clear
https://www.thealphadev.com/2022/12/javascript-console-tricks.html?utm_source=reactdigest&utm_medium&utm_campaign=1492 5/8
23/1/23, 9:23 JavaScript Console Tricks
5:02
console.log('Hello world!');
console.clear();
console.log('This log message will
appear after the console is
cleared.');
console.profile
To evaluate the effectiveness of a piece of code, use the
console.profile and console.profileEnd methods. This might
be helpful for pinpointing performance bottlenecks and
accelerating and streamlining your code.
console.profile('MyProfile');
// Run some code that you want to
measure the performance of
for (let i = 0; i < 100000; i++) {
// Do something
}
console.profileEnd('MyProfile');
Conclusion
Don't limit yourself to using console.log; the JavaScript
console object offers a wealth of additional useful and
https://www.thealphadev.com/2022/12/javascript-console-tricks.html?utm_source=reactdigest&utm_medium&utm_campaign=1492 6/8
23/1/23, 9:23 JavaScript Console Tricks
Tags Javascript
Facebook Twitter
Shubham Guleria
A full stack web developer with knowledge
of Desktop and mobile app development
Post A Comment
Enter comment
ABOUT US
https://www.thealphadev.com/2022/12/javascript-console-tricks.html?utm_source=reactdigest&utm_medium&utm_campaign=1492 7/8
23/1/23, 9:23 JavaScript Console Tricks
Sharing knowledge related to
Home Javascript various
Rust
development languages.
5:02
TRANSLATE CONTACT FORM MOST POPULAR
https://www.thealphadev.com/2022/12/javascript-console-tricks.html?utm_source=reactdigest&utm_medium&utm_campaign=1492 8/8