function suma(numero1, numero2, callback){
var resultado = numero1 + numero2;
/*->*/callback(resultado);
}
console.log('empieza');
//ESTO ESTA EN UN SUBPROCESO
suma(5,6,function(resultadocb){
console.log(resultadocb);
});
console.log('acaba');
/ *
At the moment of declaring the sum function, it receives 2 values that will be
replaced by the user and a third party that will invoke an anonymous function at the same time
As you can notice, the sum function executes the callback to print the sum of both numbers; however, that block of code will not be executed
even though the function is only declared but has not yet been invoked
later a message is printed by console
Now if the sum function is called and the 3 values are replaced; in this order:
1.- number1 = 5
2.- number2 = 6
3.- callback is replaced by an anopnimal function that receives a result, this being able to be any other value
When resultcb is printed, the line that makes the sum of both numbers is executed and that higher is indicated by an arrow
Once this function is executed and the result is returned, the last console.log is executed, which says
WHY IT IS EXECUTED IN THAT ORDER
Well the INICIA console.log does not depend on anyone because of that it appears
first, although the function is declared at the beginning, it is invoked
then for that and the last console.log to not be dependent on anyone
wait for the cascade reading to show