

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How does recursion function work in JavaScript?
When a function calls itself, it is called recursion and the same works for JavaScript too. Let’s see an example in which a function calls itself
Example
<html> <body> <script> function displayFact(value) { if (value < 0) { return -1; } // 0 factorial is equal to 1 else if (value == 0) { return 1; } else { return (value * displayFact(value - 1)); } } var res = displayFact(5); document.write("5 factorial = "+res); </script> </body> </html>
- Related Questions & Answers
- How does Recursion work in Ruby Programming?
- How does MySQL IF() function work?
- How does JavaScript .prototype work?
- How does issubclass() function work in Python?
- How does isinstance() function work in Python?
- How does JavaScript Variable Scope work?
- How does the bin2hex() function work in PHP?
- How does Exceptions Handling work in JavaScript?
- How does asynchronous code work in JavaScript?
- How does JavaScript work behind the scene?
- How does MySQL QUOTE() function work with comparison values?
- How does JavaScript 'return' statement work?
- How does jQuery.scrollTop() work?
- How does jQuery.scrollLeft() work?
- How does classification work?
Advertisements