Whenever I try to define an async function inside an object this way it throws a Syntax error.
let obj = {
fn: async function fn() {
return 10;
}
}
Whenever I try to define an async function inside an object this way it throws a Syntax error.
let obj = {
fn: async function fn() {
return 10;
}
}
The code you posted is syntactically correct. If you are getting a syntax error then the environment you are trying to run the code in doesn't support async functions (which is not necessarily surprising giving that this feature hasn't been officially released yet).
Solutions:
Information about which environment supports async functions can be found at https://kangax.github.io/compat-table/es2016plus/#test-async_functions .