Example of function call

Here’s an example of function call written in Javascript.

function greet(name){
 console.log(`Hello ${name}!`);
 
 greet2(name);
 console.log('Getting ready to say bye...');
 
 bye();
 
}

function greet2(name){
 console.log(`How are you, ${name}?`);
}

function bye(){
 console.log('OK bye!');
}

greet('Mina');

Steps explanation

  1. Memory to store the name Maggie and greetfunction
  2. console.log(Hello Mina!);
  3. Allocate the second memory box upon the first with:
    • function greet2
    • Name: Maggie
  4. console.log(How are you, Mina?);
  5. Pop off greet2
  6. console.log(‘Getting ready to say bye…');
  7. Add bye() to the top of the stack
  8. console.log(‘OK bye!');
  9. Pop off bye()
  10. Return greet function
  11. Finish call stack