How to find a factorial number in javascript

Hi, in this javascript tutorial we will learn how to find the factorial number in javascript. This is a common interview question that how to find the factorial number using recursion.

If you have no idea what is recursion my request to you please google a bit about recursion and read about it. It’s a bit tricky but believe me, it’s very important to understand Recursion in Programming. You can use this concept in any programming language.

Let me share with you some links about Recursion:

Link 1:
Link 2:

Don’t scare.. just read maybe it looks scary.

it’s an idea is that we will divide our problem into smaller problems and we will solve those small problems when all the problems are solved then we will add those results from that smaller problems and then finally we will get our output.

it’s a pretty basic idea. After reading I hope you will get it. Best of luck to you.

So here also we will use a recursive way to find the factorial number.

In the above method we used a ternary operator instead of if else statement. If you are a newbie and you think it’s a bit hard to understand down here I got a if else version for you. Buyaaaa…

output will be 120

This is a very common interview question and a very good practice for programmers specially for beginners. So keep yourself curious and try to solve more problems like this. If you still have any questions or advice just comments below. I would love to hear from you.

Leave a Reply

Notify of