JavaScript map() function returns undefined

15 minutes wasted… and it wasn’t even JavaScript’s fault. I was convinced something was wrong with map(). My array looked fine. But this kept printing in my console: [undefined, undefined, undefined] Here’s what I wrote: const doubled = numbers.map((num) => {  num * 2; }); Turns out… I forgot one word: 𝗿𝗲𝘁𝘂𝗿𝗻 When you use { } in map(), you need an explicit 𝗿𝗲𝘁𝘂𝗿𝗻. That tiny detail cost me time. Now I always check one thing: Am I returning something or just running code? A small mistake, easy to miss, yet still humbling. What’s a JS bug that made you question your sanity? 👇   #JavaScript #FrontendDevelopment #WebDevelopment #CodingTips #JuniorDevelopers #LearnToCode #Programming #CodeDebugging #DeveloperLife #CleanCode

  • graphical user interface, application

So easily done Kabika Simasiku. But it feels so good when you find the problem!

To view or add a comment, sign in

Explore content categories