Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
Can you help me I want to print the value of factorial 4 but the following function is always giving NAN why?

My question is about recursive function why it is showing always NAN instead of showing the value of factorial 4.

function factorial(i){
              if (i == 1) { return;}  
              return i * factorial(--i);};        
      console.log(factorial(4));
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

function factorial(i){
              if (i == 1) { return 1;}  
              return i * factorial(--i);};        
      console.log(factorial(4));

That right.

about 4 years ago · Juan Pablo Isaza Report

0

if (i == 1) { return;} you should return a number here like return 1;

function factorial(i){
              if (i == 1) { return 1;}  
              return i * factorial(--i);};        
      console.log(factorial(4));

small version of code:

const fact = (num) => num ==1 ? 1 : num * fact(--num);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!