Hacker News new | ask | show | jobs
by depressedpanda 296 days ago
No, I think you misunderstand how it works. The problem is that task 4, as you call it, runs after the navigation triggered by the redirect value.

The the author expects the side-effect -- navigation to a new page -- of the window.location.href setter to abort the code running below it. This obviously won't happen because there is no return in the first if-statement.

1 comments

There is a return, it's disguised as "await"

*simplified*, the symantics of "await" are just syntactic sugar

    const value = await someFunction()
    console.log(value);
is syntactic sugar for

    return someFunction().then(function(value) {
      // this gets executed after the return IF
      // something else didn't remove all events like
      // loading a new page
      console.log(value);
    });