" I promise to do this whenever that is true. If it isn't true, then I won't."
This is a simple illustration of JavaScript Promises. Sounds like an IF statement? We’ll soon see a huge difference.
- A promise is used to handle the asynchronous result of an operation.
- JavaScript is designed to not wait for an asynchrnous block of code to completely execute before other synchronous parts of the code can run.
For instance, when making API requests we have no idea if servers are offline or online & how long it takes to process server request. With Promises, we can defer execution of code until async request is completed. This way, other operations can keep running without interruption
Promises have three states:
- Pending: This is the initial state of the Promise before an operation begins
- Fulfilled: This means the specified operation was completed
- Rejected: The operation did not complete; an error value is usually thrown
Lets create promise,
If weather is true, resolve the promise returning the data dateDetails, else return an error object with data Bad weather, so no Date.
Using Promises
Using a promise that has been created is relatively straightforward; we chain .then() and .catch() to our Promise like so:
Since the weather value is true, we call mydate() and our console logs read:
We are going on a date!
{
name: 'Cubana Restaurant',
location: '55th Street'
table: 5
}
They come in handy a lot when making API requests and event handling. You can learn more about using promises is on below link :
1. Indeed: Best Overall 2. AngelList: Best for Startup Jobs 3. LinkedIn: Best for Connecting Directly With Recruiters 4. LinkUp: Best for Up-to-Date Listings 5. Scouted: Best for Recent College Graduates 6. Snagajob: Best for Hourly Jobs
7. Monster: Runner-Up, Best Overall 8. Glassdoor: Best for Employer Insights 9. FlexJobs: for Remote Jobs 10. The Ladders: Best for Experienced Managers 11. Google for Jobs : job search feature, making it possible for job seekers to search for positions straight through Google
JavaScript is a text-based programming language used both on the client-side and server-side that allows you to make web pages interactive. The general-purpose core of the language has been embedded in Netscape and other web browsers.
Q2. Is JavaScript a case-sensitive language?
Yes, JavaScript is a case sensitive language. The language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.
According to stackoverflow’s survey 2020, JavaScript is the most commonly used language for the 8th year straight with 67.7% people opting for it. The major reason for its popularity is the fact that its versatile & can be used for both frontend & backend as well as for testing.
8. JavaScript drawing 9. Reminder app 10. Google home page Clone 11. Tribute page 12. Survey form 13. Exit plugin 14. Weather app
15. Social share buttons 16. Toast notifications 17. AJAX-style login 18. Word counter 19. Countdown timer 20. Modal pop-ups 21. Address book 22. The Movies Dashboard 23. Tic Tac Toe Game 24. E- commerce Site 25. Color picker jumbtron