+ 6

Can you help me explain how this code works in JavaScript?

function fib(num){ if (num<=2) return 1; return fib(num-1)+fib(num-2); } alert(fib(6)); /* This code output 8. I'm learning programming by myself about 1 month. I try so hard to understand how it work but I can't. If it too long to write somethings easy to explain it so please tell me what I have to learn to understand that code. Thank you so much. */

18th Jan 2018, 7:51 AM
Tran Huu Dang
Tran Huu Dang - avatar
2 Antworten
+ 7
That is a challenge question in JS course, I'm not create that code so I didn't figure out even .. You know, but I think I need to learn more about something related to "self-invoking" of function. Thank for your help, I can see you are a enthusiastic person. Best luck to you:)
18th Jan 2018, 12:23 PM
Tran Huu Dang
Tran Huu Dang - avatar
+ 2
here is your question 👇👇but it outputs undefined https://code.sololearn.com/W1LNSuyz4A0k/?ref=app i dont know if you framed the question well but i tried my best to answer.....even though am not quite good in this stuff
18th Jan 2018, 9:36 AM
_c0d£ Bit£_
_c0d£ Bit£_ - avatar