Click here to Skip to main content
15,885,048 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello is it possible to call a funcion inside the same funcion itself using javascript like

funcion sample(){
some code......
...
...
sample();

}
Posted
Comments
Thanks7872 12-Feb-15 6:56am    
Why? What are you going to do?
venkat teja 12-Feb-15 11:31am    
hello actully my code is like below formet

function sample(){
if(){ some code... sample();}
else(){}

}

here need to excute else case after if condition that y..
Thanks7872 12-Feb-15 13:15pm    
Then remove if else. No need to call function twice.

Hi,

Yes it is possible, it's know as a recursive function.

Have a look here or here for an example and explanation.

... hope it helps.
 
Share this answer
 
Comments
Thanks7872 12-Feb-15 13:17pm    
I don't think recursion would be helpful to OP. See his comment below the question.
hypermellow 13-Feb-15 4:01am    
What do you mean? ... an explanation, with links to the definition of recursion is completely relevant to the posted question.
The OPs later comment was in response to your question.
Thanks7872 13-Feb-15 4:19am    
I just wanted to let you know the OP's exact issue. I mean that recursion will not help him in any way.
hypermellow 13-Feb-15 4:26am    
Ah, I see ... thanks.
What is the OPs exact issue then? ... I thought he was asking if it was possible in Javascript to call a function from within itself?
Thanks7872 13-Feb-15 4:29am    
He wants to call else part after if part completes the execution. See my comments below the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900