Created
December 10, 2015 20:27
-
-
Save bozzmob/f5ef1c0eff9d7e7f853d to your computer and use it in GitHub Desktop.
basic-async-await.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var obj = {}; | |
console.log("hello"); | |
setObj: async function(a,b){ | |
obj.a = a; | |
obj.b = b; | |
}; | |
await setObj(2,3); | |
console.log(obj.a+obj.b); |
You can only use await
in an async function.
Update 2:
var obj = {};
console.log("hello");
let foobar = {
setObj: async function(a,b){
obj.a = a;
obj.b = b;
}
};
await setObj(2,3);
console.log(obj.a+obj.b);
Your await
MUST be in an async function:
var obj = {};
console.log("hello");
var setObj = async function(a,b){
obj.a = a;
obj.b = b;
};
async function consoleLog() {
await setObj(2,3);
console.log(obj.a+obj.b);
}
consoleLog();
@benmarch I am getting the following error-
SyntaxError: missing ; before statement on line 5
which is - obj.a = a;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update 1: