DEV Community

aliplutus
aliplutus

Posted on

My function return before executing the previous linse.

The following function return x before assigning it to res, despite I assign it in an earlier line then the return.

function newData() {
    var x: [] | any = [];
    lookup("GET", "api/post/", (res: myArrays["posts"], status: number) => {
      x = res;
    });
    console.log(x);
    return x;
  }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)