In JavaScript, what are the differences between "recursion", "a non-terminating procedure that happens to refer to itself", and "repeated scheduling"? -


this question intended canonical question/answer disambiguation descriptive term "recursion", or "recursive". , extent applicable, "a non-terminating procedure happens refer itself" , "repeated scheduling".


in javascript definitions of , differences between

  1. "recursion";
  2. "a non-terminating procedure happens refer itself"; ,
  3. "repeated scheduling"

i see term "recursion" used when function repeated calls itself, though unambiguous definition of "recursion" in javascript?

rarely have viewed terms "a non-terminating procedure happens refer itself" or "repeated scheduling" used when describing pattern of function; "recursive" or "recursion" used describe pattern within body of function call, function call made original function began process.

in javascript, when "recursion" not applicable particular function pattern; , unambiguous definitions , distinctions between "recursion", "a non-terminating procedure happens refer itself" , "repeated scheduling"?

recursion

i see term "recursion" used when function repeated calls itself, though unambiguous definition of "recursion" in javascript?

that definition seems fine, function doesn't have call directly recursive, it's execution has lead being called again. example of recursion function doesn't directly call is: calling a(); calls b(); calls c(); calls a(); again.

repeated scheduling

a function uses repeated scheduling:

function ( foo ) {   var bar;   settimeout( a, 0 );   console.log( 'hello' ); } 

it not recursive because isn't called repeatedly on same call stack. when current call stack done (which means 'hello' have been logged) , nothing else ahead of calling again in event loop, called. aside difference between synchronous , asynchronous code, important different here there ever 1 copy of foo , bar @ time, , call stack isn't growing, hence there no memory or maximum call stack size exceeded errors, there version uses recursion:

function ( foo ) {   var bar;   a();   console.log( 'hello' ); } 

in case 'hello' never printed since a calls before gets logging statement.

a non-terminating procedure refers itself

a non-terminating procedure infinite loop. referring meaningless:

function ( ) {     // never terminates     while ( true ) {         // if a() called here, or before         // loop have infinite          // recursion , stack size error     }     // if, instead, a() called here,     // have infinite-loop,     // since statement never reached } 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -