Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.") } 
like image 845
Web_Designer Avatar asked Dec 24 '10 07:12

Web_Designer


People also ask

Can you call a function from another function?

It is important to understand that each of the functions we write can be used and called from other functions we write. This is one of the most important ways that computer scientists take a large problem and break it down into a group of smaller problems.

How do you call a function inside another function in Python?

A stack data structure is used during the execution of the function calls. Whenever a function is invoked then the calling function is pushed into the stack and called function is executed. When the called function completes its execution and returns then the calling function is popped from the stack and executed.

Can I call a function inside another function C++?

Yes, we can call a function inside another function.


2 Answers

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

like image 147
Christian Avatar answered Oct 16 '22 02:10

Christian


function function_one() {   function_two();  }  function function_two() { //enter code here } 
like image 20
Luthoz Avatar answered Oct 16 '22 04:10

Luthoz