An Interest In:
Web News this Week
- March 5, 2024
- March 4, 2024
- March 3, 2024
- March 2, 2024
- March 1, 2024
- February 29, 2024
- February 28, 2024
JAVASCRIPT IMPORTANT THINGS THAT YOU WANT TO KNOW!
**
https://www.freecodecamp.org/news/async-await-in-javascript/
**
1. What is Async/Await?
Async/Await makes it easier to write promises. The keyword 'async' before a function makes the function return a promise, always. And the keyword await is used inside async functions, which makes the program wait until the Promise resolves.
2. What is promises?
Promises are used to handle asynchronous operations in JavaScript.
In another words:
A promise is a value that may produce a value in the future. That value can either be resolved or unresolved (in some error cases, like a network failure). It works like a real-life promise.
_Benefits of Promises _
- Improves Code Readability
- Better handling of asynchronous operations
- Better flow of control definition in asynchronous logic
- Better Error Handling
_A Promise has four states: _
- fulfilled: Action related to the promise succeeded
- rejected: Action related to the promise failed
- pending: Promise is still pending i.e. not fulfilled or rejected yet
- settled: Promise has fulfilled or rejected
var promise = new Promise(function(resolve, reject) { const x = "DEEPBAG"; const y = "DEEPBAG" if(x === y) { resolve(); } else { reject(); }});promise. then(function () { console.log('Success, You are a GEEK'); }). catch(function () { console.log('Some error has occurred'); });
3. What is Callback Functions?
A callback is a function passed as an argument to another function. This technique allows a function to call another function
In another words:
Callback functions are those functions that have been passed to another function as an argument.
function myDisplayer(some) { document.getElementById("demo").innerHTML = some;}function myCalculator(num1, num2) { let sum = num1 + num2; return sum;}let result = myCalculator(5, 5);myDisplayer(result);
4. What is Synchronous and Asynchronous?
Synchronous communications are scheduled, real-time interactions by phone, video, or in-person.
Asynchronous communication happens on your own time and doesn't need scheduling.
Original Link: https://dev.to/erdeepbag/javascript-important-things-that-you-want-to-know-4nk6
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To