5
0x4139
2y

TL;DR: don’t use Array.forEach use
for … of … instead.

Array.forEach is synchronous, but pass it an async function and the bastard does not await it.

I was so sure that it was sync….

Wasted 2h

Comments
  • 2
    MDN clearly states that it expects a synchronous function.
  • 4
    ...and forEach being synchronous makes sense it that doesn't wait for an async call. So nothing wrong here.
  • 0
    Why the fuck are there two ways to loop through an array?

    It's like PHP all over again!
  • 5
    @sariel there are more than two ways to loop through an array… also you can do fucked up black magic to the array you are looping through. You won’t believe the shit I’ve seen…
  • 1
    @rantsauce can you elaborate why it makes sense? I mean for me it doesn’t, i would expect that if the default behavior is sync, passing an async function it will await it, not change it’s behavior to async
  • 3
    TL;DR: don't use javascript
  • 0
    @iiii men is the thing to avoid no matter what.
  • 1
    @100110111 I think I know what you are talking about man.
  • 0
  • 0
    LOL I was stuck in debugging hell the first time that got me!
  • 0
    Of all the language based gotchas, Javascript has the fucking worst (and it’s not those so called gotchas that involve type coercion bc that’s just lack of language fundamentals)
  • 0
    @iiii why we should avoid using mdn? Is the reason that it was created by Mozilla not good enough? For me it is.

    Someone not long ago called Mozilla “internet villain”. I fully agree with this statement.
  • 0
    @macfanpl okay. Any other source of standard documentation for JavaScript?
  • 0
    @macfanpl Wtf? Mozilla's documentation is great. What's has MDN done to you?
Add Comment