I'm attempting to compose a recursive function using async/await in JavaScript. This is my code:
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 This error:
Code
let rec_value = await recursion(value-1)
^^^^^^^^^
SyntaxError: Unexpected identifier
Can someone guide me to what's the mistake in my code?
Thanks in advance!!