When to use Callbacks and Promises? [closed] - javascript

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I'm new to NodeJs and to JS actually. I coded my first application using callbacks everywhere and I reached a state where I couldn't handle the number of nested callbacks anymore (callback hell). So I searched for solutions and I read that Promises are one of the best ways to solve this problem. Btw, here's a good explanation for those who are interested: https://blog.risingstack.com/node-js-async-best-practices-avoiding-callback-hell-node-js-at-scale/
Therefore, I made a refactoring in the most critical functions using Promises and it works very well. However, I don't know if I should refactor all the application. How do JS developers do nowadays? Do they use Promises everywhere or do they keep using callbacks the most part of the time and use Promises only when there are too many nested callbacks? Is there a best practice for that?

Related

Why we use async/await in nodejs if it is already an asynchronous and in javascript also vice vera? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Sorry I am a noob and a very beginner with Javascript and NodeJS. :(
Pardon me for asking this silly question.
So I am here a little bit confused. I searched a lot but didn't get the appropriate understanding. My question is simple:
Javascript is synchronous and we use async/await for the callbacks.
Nodejs is asynchronous but also then we use async/await nodejs also.
I really don't get this. How's is it happening? Maybe someone can give me a clear picture of this with some proper and easy to understand examples.
Thanks!
Javascript and Nodejs, code written in both works synchronously. Based on functional requirement we make the execution of code asynchronous by adding async/await.

Why not make all functions async JS [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I understand async/await are really just promises but I'm curious if there's a reason not to make all functions async and await all value for consistency?
My Question
Is there any issues or implications to making all functions async? Are there any drawbacks?
This is for both Node.js and Client side systems (transpiled)
For many functions, you just want a result, and you want it now. Why would you go through all the extra overhead and complexity of async?
In other words, yes there are implications: there is almost certainly going to be a performance hit; partly because the code will be more complex.

Asynchronous programming in JS [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I often hear something like "working knowledge of asynchronous programming" regards JavaScript in job descriptions etc, but I'm not sure what it mean - is it about callbacks and promises or is there something else to it? I'd appreciate if someone could explain this to me.
Yes, effectively. More generally, it's about understanding the asynchronous nature of the most common JavaScript environments (web browsers, Node.js) and being fully versed in using callbacks, promises, async/await (in modern environments), etc. Understanding the closures-in-loops problem, why you can't return the result from an asynchronous call, that code that looks like it's below other code in a function may run earlier than the code apparently above it (because the code above it is in a callback), etc.

What works best when building a search application: search:search or cts:search? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I want to know that in order to make a dynamic search application which looks through all the collections and gives the users the ability to use facets, collection facets, pagination, sorting etc what should be the right approach?
I found two functions for this: search:search, and cts:search. Which matches my needs best?
search:search is built on top of cts:search (as well as other APIs). They’re designed to work together. You should start with search:search, though. It is designed specifically for your faceted search use case and includes many conveniences and best practices that might not be obvious with the lower-level APIs, for example, concurrent facet resolution and pagination. If you need to do something more sophisticated than what search:search provides out-of-the-box, you can call out to other libraries.

JQuery and WinJS - Promise [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
WinJS Promises and JQuery Promises are the same thing?
Promises are a programming pattern for dealing with asynchronous operations. The pattern could be applied to other languages, but they are most commonly encountered in JS libraries (like jQuery and WinJS).
Kraig Brockschmidt has a really good blog post about how they work (in general) and in WinJS here:
http://blogs.msdn.com/b/windowsappdev/archive/2013/06/11/all-about-promises-for-windows-store-apps-written-in-javascript.aspx
I've written a blog post comparing jQuery promises and promises in WinJS. The short answer: they're interoperable.
http://blogs.windows.com/windows/b/appbuilder/archive/2013/07/10/jquery-and-winjs-working-together-in-windows-store-apps.aspx

Categories

Resources