JavaScript idioms
2023-09-13 20:00:17.639384+02 by Dan Lyke 0 comments
RT Greg Knauss @gnkauss@mastodon.social
Since I’m new to JavaScript, I wrote:
𝚒𝚏 (𝚌𝚊𝚕𝚕𝚋𝚊𝚌𝚔) { 𝚌𝚊𝚕𝚕𝚋𝚊𝚌𝚔(); }
…like an idiot. Then, I realized I should be adapting to JavaScript culture and make it inscrutable, so I re-wrote the line to:
𝚌𝚊𝚕𝚕𝚋𝚊𝚌𝚔 && 𝚌𝚊𝚕𝚕𝚋𝚊𝚌𝚔();
But I suspected there was something even more nightmarish, and sure enough, of course. This is how real
JavaScript developers do it:
𝚌𝚊𝚕𝚕𝚋𝚊𝚌𝚔?.();
And by “real JavaScript developers,” I mean “monsters”.