Skip to content
Advertisement

How to pass parameter to a promise function

this might seem a silly question but I am a newbie in this topic. I am working on promises on node js. And I want to pass parameter to a promise function. However I could not figure it out.

JavaScript

and the function is something like

JavaScript

Advertisement

Answer

Wrap your Promise inside a function or it will start to do its job right away. Plus, you can pass parameters to the function:

JavaScript

Then, use it:

JavaScript

 

ES6:

JavaScript

Use:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement