syncTest works, await asyncTest doesn't but there's no error message, so I can't see how to fix this ?
function syncTest(a) {
return a;
}
async function asyncTest(a) {
return a;
}
async function test() {
let value1 = new Function(
`return syncTest("123");`
)();
console.log(value1);
try {
let value2 = new Function(
`return await asyncTest("123");`
)();
console.log(value2);
}
catch(e) {
console.log(error.message);
}
}
test();
2 possible problems:
Using await most likely means the function will return a Promise, not plain text. Learn about it here, you won't regret it.
Second, the "new Function" command you are using is quite odd, and most likely isn't asynchronous in this case. The await keyword only works in asynchronous functions, E.g. (async()=>{}) is an asynchronous function.
Please take this all with a grain of salt, as I am unable to test this at the moment. Just some words of wisdom! ✨