JS API
Sraban Pahadasingh June 25, 2024 01:06 AMsetTimeout()
Executes a function after a specified delay.
- Example:
setTimeout(() => {
console.log('Executed after 1 second');
}, 1000);
fetch()
Used for making network requests. It returns a Promise
that resolves to the response.
- Example:
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data));
Promise()
Represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
- Example:
const promise = new Promise((resolve, reject) => {
const success = true;
if (success) {
resolve('Operation successful');
} else {
reject('Operation failed');
}
});
promise.then(result => console.log(result))
.catch(error => console.log(error));