I'm new to ES6 and Node.js
I would like to understand how callback functions work in a synchronous environment and asynchronous environment.
I tried to run the following in Node:
function func1() {
console.log('hello');
}
func1(function(){
console.log('world');
});
From my understanding of asynchronous callbacks, func1 should execute first, and when func1 finishes execution it calls back the function inside its argument list.
So in this case:
console.log('world')
should execute in second place, but i'm only getting as an output:hello
.
Am i missing something? Can someone explain to me with clear examples how callbacks work? Is it the same in a synchronous environment?