Skip to content

Instantly share code, notes, and snippets.

@Hurly77
Created April 9, 2021 00:55
Show Gist options
  • Save Hurly77/0e45171efbde0aa99416836d5d6861e1 to your computer and use it in GitHub Desktop.
Save Hurly77/0e45171efbde0aa99416836d5d6861e1 to your computer and use it in GitHub Desktop.
//lets make a function the returns Hello would
const add = (a, b) => {
if(a && b){
return a + b
}
return 'No Numbers'
}
const subtract = (a, b) => {
if(a, b){
return a - b
}
return 'No Numbers '
}
const addAndSubtract = (a, b) => {
let num1 = add(a, b)//=> 1500
let num2 = subtract(a, b)//=> -500
return num1 + num2 /// 1500 + (-500) = 1000
}
addAndSubtract(500, 1000)
//=> 1000
//so the call stack would look like this.
|addAndSubtract|
//addAndSubtract is placed on the stack, then if we step inside this function the stack will look like this:
|add |
|addAndsubtract|
//after execution, it will go to the next line of code and execute subtract.
|subtract |
|addAndsubtract|
// once there is no code left inside the function we return a number and the function is poped of the stack.
|addAndSubtract|
// not paused
//=> The first function that gets call is addAndSubtract function, we then set inside the function scope and we get two new functions added to the stack.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment