im learning javascript, and i have been following some video tutorial on youtube
this is the original code
function add(first, second, callback){
console.log(first+second);
callback();
}
function logDone(){
console.log("done");
}
add(2,3,logDone);
and the result of code on above is
5 main.js (line 4)
done main.js (line 9)
and i make slight change to the code into this
function add(first, second, callback){
console.log(first+second);
callback;
}
function logDone(){
console.log("done");
}
add(2,3,logDone());
and the result is this
done main.js (line 9)
5 main.js (line 4)
my question are:
could you explain to me why i got the result pile up that way?,
and what the difference if we call a function with the bracket () and without the bracket ()?
callback();line.foo(bar()),baris called first and its return value is passed tofoo. Is btw is how most programming languages work.