How do I call a function inside of another function?

I just want to know how to call a javascript function inside another function. If I have the code below, how do I call the second function inside the first?

function function_one()
{
alert("The function called 'function_one' has been called.")
//Here I would like to call function_two.
}

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

Answers:

Answer

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).

Answer
function function_one() {
  function_two(); 
}

function function_two() {
//enter code here
}
Answer

function function_one()
{
    alert("The function called 'function_one' has been called.")
    //Here u would like to call function_two.
    function_two(); 
}

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

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.