Are built-in functions inline on the call stack?

I am new to js and reading an eloquent javascript book, but the call stack part is confusing to me. This is some sample code:

debugger;
function greet(who) { 
debugger;
  console.log("Hello " + who);
}
debugger;
greet("Harry");
debugger;
console.log("hi");  
console.log("bye");

      

This is what I observed, the debugger and console.log are anonymous call. the greet function is defined in the global scope, but when I hit line 7, is there still an anonymous call on the stack and the greet function gets pushed onto the stack? but why is it anonymous? can someone please tell me more about the call stack and what's going on here?

+3


source to share


1 answer


All code that is on top (not in the function) is automatically moved to the inner function using the JS engine. Your code will be converted to:

(function() {
    debugger;
    function greet(who) { 
        debugger;
        console.log("Hello " + who);
    }
    debugger;
    greet("Harry");
    debugger;
    console.log("hi");  
    console.log("bye");
})();

      



It is an anonymous function at the bottom of the call stack.

+3


source







All Articles