0% found this document useful (0 votes)
3 views1 page

notes - Copy_page-0001

The document explains the preventDefault() method in JavaScript, which stops the default behavior of events like clicks and form submissions. It also covers the async and await keywords, which are used to handle asynchronous operations in a more readable manner, with async functions returning Promises and await pausing execution until a Promise is settled. Key points include that async functions always return a Promise and that await can only be used within async functions.

Uploaded by

sumit78599
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

notes - Copy_page-0001

The document explains the preventDefault() method in JavaScript, which stops the default behavior of events like clicks and form submissions. It also covers the async and await keywords, which are used to handle asynchronous operations in a more readable manner, with async functions returning Promises and await pausing execution until a Promise is settled. Key points include that async functions always return a Promise and that await can only be used within async functions.

Uploaded by

sumit78599
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 1

preventDefault:- preventDefault() means that

when an event occurs (e.g. button click, form submit,


or keyboard press), to prevent the default behavior of
our event. When you use preventDefault() , you
prevent the browser or any other software from
performing our action.

Async and Await:-


Theory of async and await in JavaScript

async and awa it are


used to handle asynchronous operations in JavaScript in a cleaner and more
readable way, making asynchronou s code behave more like synchronou s code.

1.async Keyword

• Purpose: The asyn c keyword is used to define an asynchronous function.


• Return Value:An async function always returns a Promise, which is either resolved with
the return value of the function or rejected if an enor is thrown.
• Function Behavior: Even though an asyn c function executes asynchronou sly, the result
ishandled like a regular function but with Promise-based behavior.

Key Points:

• The async keyword ensuresthat the function returns a Promise, even if the function does
not explicitly return a Promise.
•Itallows for the use of the awa it keyword inside the function.

Example:

async f un ct ion example ( ) {


return "Hello , Wo rld !";

example () .then ( ( result ) => console .log ( resu lt ) ) ; II Outpu ts : "Hello , Wor ld !"

2.await Keyword

• Purpose: The await keyword is used inside async functions to pause execution until a
Promise is resolved or rejected.
• Behavior:When await is used, the function execution is paused, and JavaScript waits for
the Promise to settle before proceeding.

You might also like