DEV Community

Discussion on: What is the most confusing 💡thing in JavaScript?

Collapse
 
briankephart profile image
Brian Kephart

Return statements.

I write more Ruby than JavaScript. In Ruby, every expression returns an object, so explicit return statements are rarely used. In JavaScript, I always forget to explicitly return something from a function.

This by itself isn't really confusing, but then I get confused between:

return something()

and:

return function () {
  something()
}

Something about the scoping of function calls still hasn't clicked for me yet in JS, so I always end up trying a variety of return statements until the code executes as intended. This would probably all make perfect sense if I wrote JS more often, but as an occasional dabbler this is what eats up my time.