This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# == Schema Information | |
# | |
# Table name: accounts | |
# | |
# id :bigint not null, primary key | |
# balance :integer | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function main(){ | |
console.log("I'll have my breakfast"); | |
setTimeout(() => { | |
console.log("I'll have my lunch"); | |
}, 0); | |
console.log("I'll have my dinner"); | |
} | |
main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function myFirstAsyncFunction(){ | |
return "Hello" | |
} | |
myFirstAsyncFunction().then((result) => { | |
console.log(result); | |
}); | |
// Output | |
// Hello |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function callDogApi(url){ | |
const promise = fetch(url); | |
promise.then((response)=> { | |
if(response.status === 200){ | |
console.log('Api call successful'); | |
console.log(response); | |
}else{ | |
throw new Error(response.status); | |
} | |
}).catch((error)=> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getData(url){ | |
const response = await fetch(url); | |
console.log(response); | |
} | |
getData('https://dog.ceo/api/breeds/image/random'); | |
getData('https://dog.ceo/api/breed/Husky/images/random'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just a normal function, not an async function. | |
function firstFunction(){ | |
return new Promise((resolve, reject)=> { | |
var randomNumber = (Math.floor(Math.random() * 100) % 2); | |
if(randomNumber === 0){ | |
setTimeout(() => { | |
resolve("Number is even"); | |
}, 3000); | |
}else { | |
setTimeout(() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Promise((resolve, reject) => { | |
console.log('Initial'); | |
resolve(); | |
}) | |
.then(() => { | |
throw new Error('Something failed'); | |
console.log('Do this'); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let promise1 = new Promise((resolve, reject) => { | |
setInterval(() => { | |
reject("This is rejected"); | |
}, 10000); | |
}); | |
promise1.catch((errorResponse) => { | |
console.log(errorResponse); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let promise1 = new Promise((resolve, reject) => { | |
setInterval(() => { | |
resolve("Resolved the promise"); | |
}, 10000) | |
}); | |
// promise.then(callback_for_resolved, callback_for_rejected) | |
promise1.then( | |
(successResponse) => { | |
console.log(successResponse); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Resolved promise | |
let promise1 = new Promise((resolve, reject) => { | |
resolve("Resolved this promise") | |
}); | |
// Rejected promise | |
let promise2 = new Promise((resolve, reject) => { | |
reject("Rejected the promise"); | |
}); |