Skip to main content
14 votes
Accepted

Using async / await with dynamic import() for ES6 modules

Approach 2 does not work because accoring to MDN: import '/modules/my-module.js'; Is how you import a module for Import a ...
Taki's user avatar
  • 618
13 votes

Stack Exchange rev​iew queue notifications

I don't see much benefit to the enum. The Notification.permission string (or the return value of requestPermission()) is already ...
CertainPerformance's user avatar
11 votes
Accepted

Pass Async function to new Promise constructor

There's simply no reason to wrap your existing promise with another promise and no reason to use await or async here either: <...
jfriend00's user avatar
  • 3,958
8 votes

Timezone-based VPN-detection

I'm not sure whether it is best to use .then(({browserTimezone, ipTimezone}) => ( ... or replace it with something like ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
6 votes
Accepted

Parallel and Sequential array looping with async/await

JavaScript's execution model My understanding is that the first one is parallel because the await applies to each invocation of the async lambda that is passed to map. This is not quite right since ...
ComFreek's user avatar
  • 771
6 votes

Baseball player statistics controller

Bearing in mind that you claim that you do not to maintain this code anymore1, there are a few suggestions I would have about this code: define functions and accept parameters- that should allow the ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
6 votes
Accepted

code duplication in conditional Promise

You could move the door.locked check into the door.unlock() function (or into a new function) which would allow you return a promise for both cases: ...
Murray's user avatar
  • 198
6 votes
Accepted

Timezone-based VPN-detection

Use modern JavaScript Use async functions rather than .then and .catch callbacks. Use arrow ...
Blindman67's user avatar
  • 22.9k
5 votes

Javascript progress bar in succession

Your code already looks pretty clean. Good work! There are only a few things I would recommend changing. Don't define timings in CSS that should be defined in JavaScript. In this specific case using ...
Gerrit0's user avatar
  • 3,501
5 votes

Stack Exchange rev​iew queue notifications

Usability I ran the script on the SO review dashboard to see how it would perform with various numbers. The biggest thing I noticed was that it didn't properly handle numbers greater than 999 since ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
5 votes
Accepted

Passing data from one promise to another using then

You could do like so if you prefer, essentially just pass forward the data i the promises. You could write your own promiseAllObject if you want it to be slightly neater. ...
SomeGuy's user avatar
  • 66
5 votes

await user input with async/await syntax

First of all, I would not use Promises to do event based programming. It is not used like that, so your code will get harder to follow. Also, I would advise you to split up your functions more and ...
MauriceNino's user avatar
4 votes

Nested loop with synchronous and asynchronous behavior

First you can make the database container more precise and accessible if you define it like this: ...
char bugs's user avatar
  • 171
4 votes
Accepted

Return a Promise for a JSON POST

Given this method, we don't know which syntax is the more appropriate. Neither is appropriate as both your options employ promise anti-patterns (creating new promises when you can just work with and ...
jfriend00's user avatar
  • 3,958
4 votes

Check if images are loaded (ES6 Promises)

Sounds like a use case for Promise.allSettled(). The Promise.allSettled() method returns a promise that resolves after all of ...
AFoeee's user avatar
  • 141
4 votes
Accepted

JavaScript / Express error handling w/ promises

There's a big problem here. getUserByEmail() can either return a promise or throw synchronously which is a bad design and very unfriendly for the caller. Instead, ...
jfriend00's user avatar
  • 3,958
4 votes
Accepted

Fetching user details, posts, and comments using promises in ExpressJS

If you use 1 promise, you would encounter a long chain of then method and all of async operations would be executed in sequence style which increases response time. If you create 3 promises, all of ...
tanapoln's user avatar
  • 156
4 votes
Accepted

Read files from a directory using Promises

For the most part, your use of promises is idiomatic. Good work! Most people new to promises fail to chain them and end up with a similar pyramid to your original code. ...
Gerrit0's user avatar
  • 3,501
4 votes
Accepted

Read files from a directory using Promises V2

First of all, async code is not a requirement for all Node.js code. It depends on the use case. Async code makes sense if you want to service multiple things concurrently (i.e. HTTP servers, test ...
Joseph's user avatar
  • 25.4k
4 votes
Accepted

Function to find user's region based on GPS coordinates

The callback supplied to geocode has a lot of code in it. This becomes difficult to test independently of testing the rest of ...
Dan's user avatar
  • 3,788
4 votes
Accepted

Upvote/counter in Javascript

Consistency Sometimes you use snake_case and sometimes you use camelCase: in JavaScript we usually use camel case, it's not mandatory but stick to one. Then, for example, ...
Adriano Repetti's user avatar
4 votes
Accepted

Javascript class to geocode Dutch addresses

Using Promise when async/await is supported is a sign of an anti-pattern. The only case you ...
Joseph's user avatar
  • 25.4k
4 votes

Extending native JavaScript Promise with cancellation support

You can override the executor and can pass an onCancel function to it like following: ...
vivekfyi's user avatar
  • 141
4 votes
Accepted

Retry a Promise resolution N times, with a delay between the attempts

Call stack / Job queue / Event queue Calling an async function does not use the call stack in the way you may be used to. Rather the async call remains on the ...
Blindman67's user avatar
  • 22.9k
4 votes
Accepted

Throttling promise execution (API requests, etc)

The most important advice I can offer is to turn on strictNullChecks and noImplicitAny. Without these settings, TypeScript's ...
Gerrit0's user avatar
  • 3,501
4 votes

Nested cross-origin iframes for secure user-configurable javascript tools

From a medium review; host.html Not a big fan of inline script tags Not sure why there are 2 <script> tags, I would merge them You seem to practice a bit of ...
konijn's user avatar
  • 34.3k
4 votes

Implementing `Promise.all()`

Good job using const for values, as well as let for re-assignable values like ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
4 votes

Best approach on handling function that returns either a promise or just synchronous code

You really don't want a function sometimes returning a promise and sometimes returning a value. That just makes it difficult for the caller. Instead, if you sometimes have a promise to return, then ...
jfriend00's user avatar
  • 3,958
4 votes
Accepted

Implement jquery like functions addClass, removeClass and delay in Javascript

Mutating built-in prototypes is not a good idea. It's not only inelegant, it can also lead to conflicts when other scripts on the page expect the prototypes to be unmutated. (It can even damage future ...
CertainPerformance's user avatar
4 votes
Accepted

await user input with async/await syntax

You should use observables and the myriad of functions available for them. It's called reactive programming, but I think it might fall into the category of functionalish. An example from memory: ...
Dom's user avatar
  • 226

Only top scored, non community-wiki answers of a minimum length are eligible