Must known Dev tricks!

Make It BIGGER Mortyyy!

image/svg+xml

Console tricks

// Regular

console.log('Hello');

// Interpolated

console.log(`Hello ${var}`);

// Styling

// Just use %c in the beginning and then pass css rule as second arg

console.log("%c I'm some great text", 'font-size:40px;');

// Warning

console.warn("Don't do it man!")

// Error

console.warn("I warn you! Now you got an error!")

// Info

console.info("Looks like somebody write too much code and doesn't sleep enough")

// Tesing

console.assert(1===2, 'that's wrong!')

// Clearing

console.clear()

// Viewing DOM Elements

// .dir show DOM elem in dropdown obj view

const p = document.querySelector('p');

console.dir(p)

// Grouping object

// Use .group and .groupEnd to grouping some strings. Use .groupCollapsed

const dogs = [{ name: 'Snickers', age: 2 }, { name: 'hugo', age: 8 }];

dogs.forEach(dog => {

console.group(`${dog.name}`)})

console.log(`Dog's name is ${dog.name}`)})

console.log(`Dog's age is ${dog.age}`)})

console.groupEnd(`${dog.name}`)})

// Use .count for counting use of string or object in console

console.count('Dimas')

console.count('Dimas')

// Use .time for checking time of executing operation and .timeEnd to end

console.time('fetching data')

...fetch some data

console.timeEnd('fetching data')