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?
Promise resolve() method: Any of the three things can happened: If the value is a promise then promise is returned. If the value has a “then” attached to the promise, then the returned promise will follow that “then” to till the final state. The promise fulfilled with its value will be returned.
What does that log "Uncaught (in promise)" mean? It means that there was an error in one of our promises, but we did not write any code in order to handle that error and try to catch it.
This is a common JavaScript error that happens when you try to call a function before it is defined. You get this error when you try to execute a function that is uninitialized or improperly initialized . It means that the expression did not return a function object.
You need to instantiate the Promise
.
In this case:
const p = new Promise((resolve, reject) => { resolve('ok') }) p.then(resp => console.log(resp))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With