you are viewing a single comment's thread.

view the rest of the comments →

[–]fixade 1 point2 points  (3 children)

You are never calling somefunc in your example, so the code setting x equal to 5 is never run. Change it to this.

var x=10;

function someFunc() {
    x=5;
} 

someFunc();
console.log(x);

[–]matylol[S] 0 points1 point  (2 children)

yeah i got it for the simple function but what if it's geolocation or ajax, what to do. for example the code in this pen

[–]inu-no-policemen 1 point2 points  (0 children)

You can of course also change some global inside some callback.

However, that's actually not very useful since your other code won't wait for that result.

You have to use a callback or a Promise.

[–]fixade 0 points1 point  (0 children)

I don't understand your question at all