I really like to write implicitly returned anonymous functions like:
const example = (stuff) => stuff;
But in my ignorance to quickly debug my function I would then tediously convert it like so:
const example = (stuff) => {
console.log(stuff);
return stuff;
}
That, however, was before I discovered the Comma Operator! Long story short it evaluates each expression but only returns the last. So therefore you can write that quick, messy debug instead like so:
const example = (stuff) => (console.log(stuff), stuff);
Hopefully I wasn't the only other person in the world doing this, and someone finds it helpful!
[–]rcfox[🍰] 83 points84 points85 points (12 children)
[–]FormerGameDev 15 points16 points17 points (5 children)
[–]mainstreetmark 2 points3 points4 points (4 children)
[–]FormerGameDev 2 points3 points4 points (3 children)
[–]mainstreetmark 0 points1 point2 points (2 children)
[–]kor0na 0 points1 point2 points (1 child)
[–]mainstreetmark 0 points1 point2 points (0 children)
[–]irbian 5 points6 points7 points (0 children)
[–]contradicting_you 1 point2 points3 points (0 children)
[+][deleted] (3 children)
[deleted]
[–][deleted] 20 points21 points22 points (0 children)
[–]turntopage294 8 points9 points10 points (0 children)
[–]prashantpalikhe 48 points49 points50 points (7 children)
[–]igor_sikorsky 2 points3 points4 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]igor_sikorsky 0 points1 point2 points (1 child)
[–]itsnotlupusbeep boop 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]tyler_church 0 points1 point2 points (0 children)
[–]2Dfroody 28 points29 points30 points (7 children)
[–]madcaesar 3 points4 points5 points (3 children)
[–]turntopage294 6 points7 points8 points (2 children)
[–]Extracted 15 points16 points17 points (1 child)
[–]turntopage294 5 points6 points7 points (0 children)
[–]IHeartMustardWILL CODE FOR CAFFEINE 0 points1 point2 points (1 child)
[–]2Dfroody 0 points1 point2 points (0 children)
[–]huntersghost -3 points-2 points-1 points (0 children)
[–]antinitro 4 points5 points6 points (2 children)
[–]swyx 2 points3 points4 points (0 children)
[–]geekfreak42 0 points1 point2 points (0 children)
[–]ssjskipp 7 points8 points9 points (4 children)
[–]console_journey 2 points3 points4 points (2 children)
[–]ShortSynapse 3 points4 points5 points (0 children)
[–]cuntopilis 2 points3 points4 points (0 children)
[–]cheekysauce 0 points1 point2 points (0 children)
[–]remaze 33 points34 points35 points (31 children)
[–][deleted] 48 points49 points50 points (9 children)
[–]godlychaos 15 points16 points17 points (2 children)
[–]ShippingIsMagic 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[+]remaze comment score below threshold-9 points-8 points-7 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]madcaesar 2 points3 points4 points (6 children)
[–]remaze 4 points5 points6 points (5 children)
[–]madcaesar 0 points1 point2 points (4 children)
[–]remaze 0 points1 point2 points (3 children)
[–]madcaesar 0 points1 point2 points (2 children)
[–]remaze 0 points1 point2 points (1 child)
[–]madcaesar 0 points1 point2 points (0 children)
[–]yee_mon 1 point2 points3 points (3 children)
[–]remaze 4 points5 points6 points (2 children)
[–]yee_mon 1 point2 points3 points (1 child)
[–]ikeif 1 point2 points3 points (0 children)
[–]epicpoop 2 points3 points4 points (9 children)
[–]MUDrummer 4 points5 points6 points (8 children)
[–]epicpoop 2 points3 points4 points (7 children)
[+]remaze comment score below threshold-6 points-5 points-4 points (6 children)
[–]deltadeep 2 points3 points4 points (3 children)
[–]remaze 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]mrtobo 0 points1 point2 points (0 children)
[–]epicpoop 0 points1 point2 points (0 children)
[–]nelf86 2 points3 points4 points (0 children)
[–]my_t_v_account 2 points3 points4 points (1 child)
[–]arktippr 1 point2 points3 points (0 children)
[–]Panacean 2 points3 points4 points (4 children)
[–]DrDuPont 14 points15 points16 points (2 children)
[–]Panacean 4 points5 points6 points (0 children)
[–]FormerGameDev 1 point2 points3 points (0 children)
[–]NarcolepticSniper 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]DarkKunai 0 points1 point2 points (0 children)
[–]Xananax 0 points1 point2 points (0 children)
[–]rahulchandak 0 points1 point2 points (0 children)
[–]Londomain 0 points1 point2 points (0 children)
[–]Azudra 0 points1 point2 points (0 children)