I'm trying to write a recursive function using async/await in JavaScript. This is my code:
async function recursion(value) {
return new Promise((fulfil, reject) => {
setTimeout(()=> {
if(value == 1) {
fulfil(1)
} else {
let rec_value = await recursion(value-1)
fulfil(value + rec_value)
}
}, 1000)
})
}
console.log(await recursion(3))
But I have syntax error:
let rec_value = await recursion(value-1)
^^^^^^^^^
SyntaxError: Unexpected identifier