JavaScript --Example #10 from John Resig`s Learning Advanced JavaScript -


I'm reading John Resize s "learning advanced JavaScript" and came to this function below Was that i do not understand

Screaming the function is called with the argument of 4. When this is done, then logic 4 is run through a four-operator. If it is bigger than zero, which is, then we come to yell (n-1) + a My questions are related to this.

a) yell

b) If you get the result of (n-1) + a, you get 3a javascript 3a To "aaa" I ask because of it because it says that yell (4) == "hea"

c) after converting it, what do Does it somehow add it to "hia"? I do not understand how

d) If Javascript converts 3a into string of "AAA" S., and somehow manages to add it to "hiy", then I do not understand That's why yell (4) = Hia Yale (N-1) + A = Hia (3a), hia no (4 "a" s)

As you can see I completely I'm confused.

  function Yale (n) {return n> 0? Shout (N-1) + "A": "is"; } Insist (shouting (4) == "hiya", "is calling the function by itself naturally.");  

a) This function is taking advantage of recursion, yes, the function calls again And the rest is pushed onto the stack which is waiting for the return value. B) No, the function is called with the stated value mentioned above. C) See above. D) It is not.

Think it like this:

  function A (val) {return val + "a"; } Function B (Val) {Return A (Val) + "A"; }   

If you call B ("Hua") then you will get shake. Instead of calling a different function, call it the same.

Comments