How exactly does this recursive function work in JavaScript?

前端 未结 7 1257
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 19:27

I have the following example of a recursive function, and what I don\'t understand is the order in which things are happening:

function power(base, exponent)         


        
7条回答
  •  不知归路
    2020-12-10 19:41

    As with any recursive function, the return from a particular "instance" happens when the return value has been calculated. This means that the recursed versions will then have been calculated.

    So if you pass in an exponent of 4, there will be at some point 4 copies of the function being executed at one time.

提交回复
热议问题