I just learnt “async” that “async” ensures that the function returns promise then i tried to make a promise with writing “async” instead of writing “new Promise” and it didn’t work out so i want to know is it wrong syntax or it will never work out and i will have to write only new promise?
// This is a code
async function gets(){ let gets1 = async()=>{ return 45; } gets1.then((value)=>{ console.log(value, "inside gets1") }) } gets()
Advertisement
Answer
You forgot to call the function
It should be gets1().then()
and not gets1.then()
async function gets(){ let gets1 = async()=>{ return 45; } gets1().then((value)=>{ console.log(value, "inside gets1") }) } gets()