Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// time and time end
console.time("This");
let total = 0;
for (let j = 0; j < 10000; j++) {
total += j
}
console.log("Result", total);
console.timeEnd("This");
// Memory
console.memory()
// Assertion
const errorMsg = 'Hey! The number is not even';
for (let number = 2; number <= 5; number += 1) {
console.assert(number % 2 === 0, {number: number, errorMsg: errorMsg});
}
// Count
for (let i = 0; i < 11; i++) {
console.count();
}
// group & groupEnd
console.group();
console.log('Test message');
console.group();
console.log('Another message');
console.log('Something else');
console.groupEnd();
console.groupEnd();
// Table
const items = [
{
name: "chair",
inventory: 5,
unitPrice: 45.99
},
{
name: "table",
inventory: 10,
unitPrice: 123.75
},
{
name: "sofa",
inventory: 2,
unitPrice: 399.50
}
];
console.table(items)
// Clear
console.clear()
// HTML Element
let element = document.getElementsByTagName("BODY")[0];
console.log(element)
// Dir
const userInfo = {"name":"John Miller", "id":2522, "theme":"dark"}
console.dir(userInfo);
// Color
console.log('%cColor of the text is green plus small font size', 'color: green; font-size: x-small');
// pass object, variable
const userDetails = {"name":"John Miller", "id":2522, "theme":"dark"}
console.log("Hey %s, here is your details %o in form of object", "John", userDetails);
// Default
console.log('console.log');
console.info('console.info');
console.debug('console.debug');
console.warn('console.warn');
console.error('console.error');
@dev-oswld

This comment has been minimized.

Copy link

@dev-oswld dev-oswld commented Dec 17, 2019

Thank you!

@Harshmakadia

This comment has been minimized.

Copy link
Owner Author

@Harshmakadia Harshmakadia commented Dec 18, 2019

Thank you!

Welcome! 😄

@juanpumpkinpie

This comment has been minimized.

Copy link

@juanpumpkinpie juanpumpkinpie commented Dec 28, 2019

Nice Repo! it can be great if you attached a readme file with the url description

@mforgaian

This comment has been minimized.

Copy link

@mforgaian mforgaian commented Dec 28, 2019

:) Thanks. Nice collection of all console methods with use-cases in one place.

@Harshmakadia

This comment has been minimized.

Copy link
Owner Author

@Harshmakadia Harshmakadia commented Dec 29, 2019

Thanks @mforgaian 😄
@JhonStark - I've added the link to my article in the title above as I cannot add readMe file here since this is a gist.

@andrewstyle22

This comment has been minimized.

Copy link

@andrewstyle22 andrewstyle22 commented Jan 12, 2020

Thank you!!!!!

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jan 25, 2020

Awesome

@brunormferreira

This comment has been minimized.

Copy link

@brunormferreira brunormferreira commented Feb 19, 2020

Amazing! Thanks.

@benjaminudoh10

This comment has been minimized.

Copy link

@benjaminudoh10 benjaminudoh10 commented Jun 5, 2020

Really nice collection you got here. Thanks.

I think you made a type on line 11. console.memory is not a function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment