Quick Tip to Console-Logging Arrow Functions

The problem with one-line arrow functions is that if you want to debug them with console.log, it's fairly annoying since you have to add curly braces and a return statement.

Let's take the following function:

const foo = (bar) => bar.do();

If you want to see what's in bar, you commonly have to do something like this:

const foo = (bar) => {
 console.log('bar: ', bar);
 return bar.do();

Now check this 🧙:

const foo = (bar) => console.log({bar}) || bar.do();

We utilize that console.log always returns undefined (being falsey), and thus the second bit of the or operator gets executed. No more annoying line breaks and stuff – add console.log() || in front of your function body.