2
y33tr
5y

node/JS is retarded
TIL that you can call return multiple times but it wont break

6 hours down the drain

Comments
  • 0
    No that doesn't seem right. Did you call it from a function?
  • 0
    Wait what
  • 0
    @ScriptCoded was probably done wrong (i dont do js)
  • 0
    Array.some()
  • 0
    This problem is so typical that now whenever I want to put a return I search between the top of the desired function and the point for "=>" and "function".
  • 1
    `forEach` accepts a function, and calls it each iteration.
    `(args) => { ... }` defines an anonymous function. Think lambda, etc. This is functionally identical to a static, named function with the exception that it lacks a name and can be assigned to a variable.

    What's happening is that you are returning from the arrow function you pass to `forEach` -- which has the effect of exiting from that particular iteration call, not exiting from the parent function or loop. You're using it like a `continue`/`next`, not a `break`.

    To illustrate it more clearly, this is what you're doing:

    ```
    function iterate(x) {
    return true; // returns from this function
    }

    function processArray(array) {
    for(var i=0; i<array.length; i++) {
    iterate( array[i] ); // evaluates to true, which is then discarded
    }
    return false; // returns from this function
    }
    ```

    `processArray(array)` will look at every element of `array` and will always return `false` after completing.
  • 0
  • 1
    @Root k thx. Devrant>StackOverflow
  • 0
    Been there. Done that.
Add Comment