JavaScript's comma operator

Vitaly Gordon explains how the little known comma operator makes it easy to add some debugging statements in short hand array functions.

What if you want to add a console.log call before x + 1 ? With comma operator, adding side-effects to functional expressions is simple:

const fun = x => (console.log (x), x + 1)

https://medium.com/@xpl/javascript-did-you-know-about-the-comma-operator-ff9b511cc33

Join 9,500+ smart developers

Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.

No spam. Unsubscribe anytime. You can also follow me on X.

Found something interesting to share? Submit a link to the community section.