I am having trouble understanding what the difference is (if any) between the below two sets of code.
function asyncDouble(num, callback) {
setTimeout(() => callback(num * 2), 1000);
}
asyncDouble(10, (x) => console.log(x));
// (after one second) logs `20`
function asyncDouble(num, callback) {
setTimeout(callback(num * 2), 1000)
}
asyncDouble(10, (x) => console.log(x));
// (after one second) logs `20`
They both work and return the correct result, but I am wondering if this means we do not have to write the entire function as the first argument to setTimeout? Just confused as to why it also works in the second example.