Calling function value inside another function in Javascript !
In this article we are going to learn about some javascript tricky problems. Before that we learn about functions in JavaScript like what function and how we can use function inside javascript.
What is function ?
Function is a block of code , it executed when something invokes like something call it.
Example:
function test(){
var x=10;
return x;
}
Now we will see about calling one function inside another function. Let suppose we have two functions func1,func2 and want to display func1 data inside func2. Any Idea how we can do that ? don’t worry we tell you about procedure.
Steps:
- Create one function name called myfunc1.
- Declare one variable or return any value inside it.
- Create one more function name called myfunc2.
- Assign func1 into one variable inside second function.
- Call console.log() or alert() function to display that value.
For more clarity see below code example you will get better understanding.
function myfunc1(){
var a =10;
retrun a;
}
function myfunc2(){
var output=myfunc1();
}
console.log(output); // get output inside browser console
or
alert(output); // get output inside dialog box.