Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Using function for promise
- function withConstructor(num){
- return new Promise((resolve, reject) => {
- if (num === 0){
- resolve('zero');
- } else {
- resolve('not zero');
- }
- })
- }
- withConstructor(0)
- .then((resolveValue) => {
- console.log(` withConstructor(0) returned a promise which resolved to: ${resolveValue}.`);
- })
- // Write your code below:
- //Using async function that will always return a promise (hence do not use the new keyword)
- //Write async function to reproduce the functionality of withConstructor() above
- async function withAsync(num){
- if (num === 0){
- return 'zero';
- } else {
- return 'not zero';
- }
- }
- withAsync(100)
- .then((resolveValue) => {
- console.log(` withAsync(100) returned a promise which resolved to: ${resolveValue}.`);
- })
- /*
- Output will show:
- $ node app.js
- withConstructor(0) returned a promise which resolved to: zero.
- withAsync(100) returned a promise which resolved to: not zero.
- $
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement