I am new to JavaScript and, am not able to understand why the output of the following code:- is:- and not:- additionally, console.log(“async executed”) is not getting lagged for 10 seconds, instead, it gets executed immediately after the two synchronous console.log Answer As commented by @trincot,…
Tag: es6-promise
How to reject child Promise using AbortController
I just learned about how to reject a Promise by using the AbortController API. It’s working fine but when the promise to reject as a “child Promise”, this one will still continue running even if the parent Promise is rejected. Is there a way, when the parent is rejected, to stop the children…
why is the following code not returning sum of all the array elements?
Below is the code, I want to return the sum of all the array elements, why is it not working. I know we don’t need the Promise to achieve that but I would like to know how it can be done with a Promise. output:[object Promise]8 Answer I hope this will help Without changing sumPromise
JavaScript Why does an inner setTimeout of a Promise runs after an outside setTimeout
When run the below code snippet, it outputs 2,1. Since Promise is a micro-task and everything inside a promise should run before a macro-task (setTimeout), I expect that the output will be 1,2. So even if there is a macro-task inside a micro-task, I thought the output will be 1,2. But it outputs 2,1. WhatR…
Why are promise function in executing in wrong order?
When I am executing separately that program gives the right solution but when I run all four it got messup. Expected Output: Getting username… Username = srishti Validating username… Valid Username! Getting password… Password = upgrad Validating password… Valid Password! BOTH VALID****…
Resolving a promise to multiple parameter values
Is it possible to resolve a promise in such a way that the next promise in the chain can be an executor that takes multiple parameters? For example, say I have a function that takes three parameters: If I’m including it in a chain, e.g. one of these: Is there something I can return (in place of /* ??? *…
Function recursion advice
I am building an employee tracking app. I want my app to work so that after each one of the functions for the various list selections is complete, the app will re-prompt you with the options list again. There are a few methods I can think of to achieve this but I was hoping a more seasoned developer could rec…
what’s the difference between using then in argument and not
what’s the difference between these two promises one is used in argument other outisde , which one is preferred Answer This is probably opinion based. I think the first one is preferred because you won’t end up with nested promises and should be easier to read. To make it more obvious: vs The numb…
Calculate Value from JS Promise
I have assigned a callback function to a variable. The function then returns a promise stating it is fulfilled and the value. I want to be able to return the value and use it to perform a mathematical calculation. Javascript code: In the console I get the below output. Answer Assuming this is the interface yo…
How to generate a zip file synchronously using JSZip?
I’m working on a React.js application, i have a loop from j=1 to j=2000 and i want to download a zip file when j=1 or j=2000. The problem is that the two zip files downloaded at the same time after the end of the loop. in other words the download of the two zip starts when j = 2000. I