Console logging tricks in es6

Updated May 26, 2024
Created September 5, 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)

Comments?