ohmybuck

Console logging tricks in es6

September 05, 2018

Console logging tricks in es6…

Easier tracing?

// eg:
console.log(x)

// Solution: Wrap in object syntax
console.log({ x })

// #=> { x: .... }

Arrow function?

// eg:
x => someFunction(x)

// Solution: Due to console.log always returning undefined, we can throw a logical operator after it to return our original function
x => console.log(x) || someFunction(x)
// or as above
x => console.log({ x }) || someFunction(x)

Written by Oliver Smit. I love talking about web technologies, good design practices, optimising productivity, and rapid prototyping of projects. Check out my work on Github