DEV Community

Discussion on: Recursion and tail recursion with JavaScript

Collapse
 
hi_iam_chris profile image
Kristijan Pajtasev

Reason for tail recursion is less usage of memory, not less calls. There will be still same number of call, but stack is getting cleared immediately

Collapse
 
ahmedsalahzero profile image
AhmedSalahZero

why would stack be cleared ? the first function does not return any thing yet and it still waiting for the last one to return its values .. am i right ?
sholud the tail recursion and head recursion work exactly the same ???