How do I call a function inside of another function?

function function_one() {
    function_two(); // considering the next alert, I figured you wanted to call function_two first
    alert("The function called 'function_one' has been called.");
}

function function_two() {
    alert("The function called 'function_two' has been called.");
}

function_one();

A little bit more context: this works in JavaScript because of a language feature called “variable hoisting” – basically, think of it like variable/function declarations are put at the top of the scope (more info).

Leave a Comment