Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4067520
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:15:35+00:00 2026-05-20T16:15:35+00:00

I m reading John Resig s Learning Advanced JavaScript http://ejohn.org/apps/learn/#10 and came across this

  • 0

Im reading John Resigs “Learning Advanced JavaScript” http://ejohn.org/apps/learn/#10 and came across this function below that I don`t understand.

The function yell is called with an argument of 4. When this is done, the argument 4 is run through the terniary operator. If it is greater than zero, which it is, then we come to yell(n-1) + a
My questions relate to this.

a) does yell(n-1) + a call the function again (i.e. restart it) with an argument of 3.

b) If you do (n-1) + a, you get a result of 3a. Does JavaScript convert 3a to “aaa”. I ask this because in the assert line it says yell(4) == "hiyaaaa"

c) after converting it, does it somehow add it to “hiy”? I don`t understand how.

d) if JavaScript does convert 3a to a string of “aaa”s, and somehow manages to add it to “hiy”, I don`t understand why yell(4)=hiyaaaa. Yell(n-1) + a = hiyaaa (3as), not hiyaaaa(4″a”s).

As you can see I am totally confused.

function yell(n){
  return n > 0 ? yell(n-1) + "a" : "hiy";
}
assert( yell(4) == "hiyaaaa", "Calling the function by itself comes naturally." );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:15:36+00:00Added an answer on May 20, 2026 at 4:15 pm

    a) This function is taking advantage of recursion, so yes, the function called again and everything else is pushed on the stack waiting for that return value.
    b) No, the function is called with a return value as mentioned above.
    c) See Above.
    d) It doesn’t.

    Think of it like this:

    function a(val) {
      return val + "a";
    }
    
    function b(val) {
      return a(val) + "a";
    }
    

    If you call b(“hiya”) you’ll get hiyaaa. Now instead of calling a different function, call the same one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I was reading up on John Resig's blog , saw his micro-templating javascript
Reading on another forum I've came across the world of CSS Frameworks. The one
Reading through this question on multi-threaded javascript, I was wondering if there would be
I'm attempting to learn some flex/bison, and I'm reading Flex & Bison by John
Reading this question I found this as (note the quotation marks) code to solve
Reading over the responses to this question Disadvantages of Test Driven Development? I got
Reading this post has left me wondering; are nightly builds ever better for a
I've been doing some reading about two (relatively) new concepts in the Javascript language
Reading the reviews at Amazon and ACCU suggests that John Lakos' book, Large-Scale C++
Reading this question , I wanted to test if I could demonstrate the non-atomicity

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.