17.11.2015 Views

JavaScript_Succinctly

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sample: sample97.html<br />

<br />

var countDownFrom = function countDownFrom(num) {<br />

console.log(num);<br />

num--; // Change the parameter value.<br />

if (num < 0) { return false; } // If num < 0 return function with no<br />

recursion.<br />

// Could have also done arguments.callee(num) if it was an anonymous<br />

function.<br />

countDownFrom(num);<br />

};<br />

countDownFrom(5); // Kick off the function, which logs separately 5, 4,<br />

3, 2, 1, 0.<br />

<br />

You should be aware that it’s natural for a function to invoke itself (aka recursion) or to<br />

do so repetitively.<br />

103

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!