async function sayHello() {
return 'Hello World';
}
sayHello().then((value) => console.log(value));
If we just had function sayHello(), then `then` doesn't make sense.
async function sayHi() {
return 'Hi';
}
async function sayHello(arg = 1) {
console.log('in say hello');
if (arg === 1) {
const inner = await sayHi();
return inner;
} else {
return 'Hello Worlds';
}
}
sayHello().then((value) => console.log(value));;
- Will wait for 'hi'
doSomething(param1, param2, function(err, paramx) {
doMore(paramx, function(err, result) {
insertRow(result function(err) {
yetAnotherOperation(someparameter, function(s) {
somethingElse(function(x) {
// ...
});
});
});
});
});
function something() {
return doSomething(param1, param2);
}
function main() {
something().then((err, paramx) => {
doMore(paramx).then((err, result) => {
insertRow(result).then((err) => {
// ...
});
});
});
}