Sunday, May 19, 2024
138
rated 0 times [  144] [ 6]  / answers: 1 / hits: 19096  / 7 Years ago, fri, november 24, 2017, 12:00:00

I got error of Uncaught TypeError: undefined is not a promise



const p = Promise((resolve, reject) => {
resolve('ok')
})

p.then(resp => console.log(resp))


https://jsbin.com/daluquxira/edit?js,console,output



what's wrong with above code?


More From » ecmascript-6

 Answers
176

You need to instantiate the Promise.



In this case:





const p = new Promise((resolve, reject) => {
resolve('ok')
})

p.then(resp => console.log(resp))




[#55849] Tuesday, November 21, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alexandreah

Total Points: 720
Total Questions: 85
Total Answers: 90

Location: Central African Republic
Member since Fri, Jun 5, 2020
4 Years ago
;