Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var test;
- // Synchronous
- test = 'before';
- // Asynchronous
- var myFunction = function (cb) {
- // Let's pretend this is network or filesystem access...
- setTimeout(function () {
- cb('after')
- }, 1000);
- }
- myFunction(function(result) {
- test = result;
- });
- // This executes out of order, because setTimeout is async
- setTimeout(function () {
- console.log(test);
- }, 2000);
- console.log(test);
- // Output:
- // > before
- // > after
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement