Skip to content

Instantly share code, notes, and snippets.

@tegila
Created January 23, 2019 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tegila/e68af3e582557ef3524590a670405c97 to your computer and use it in GitHub Desktop.
Save tegila/e68af3e582557ef3524590a670405c97 to your computer and use it in GitHub Desktop.
const func1 = (a, b, callback) => {
callback(a + b);
};
const func2 = (a, b) => {
func1(a, b, result => {
console.log(result);
});
};
func2(19, 10);
func3 = (a, b) => {
return new Promise((resolve, reject) => {
try {
if (b <= 0) throw "assim nao dá";
const c = a / b;
resolve(c);
} catch (e) {
reject(e);
}
});
};
func3(19, 0)
.then(console.log)
.catch(console.log)
.finally(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment