JavaScript: Difference between revisions

Content deleted Content added
partial undo
As a first example, direct function naming is an extra layer of complexity. Make it more obvious that functions are variables as an introduction.
Line 153:
A simple [[recursion|recursive]] function:
<syntaxhighlight lang="javascript">
functionvar factorial = function(n) {
if (n === 0) {
return 1;
Line 163:
[[Anonymous function]] (or lambda) syntax and [[Closure (Computer Science)|closure]] example:
<syntaxhighlight lang="javascript">
functionvar displayClosure = function() {
var count = 0;
return function () {
Line 177:
[[Variadic function]] demonstration (<tt>arguments</tt> is a special [[variable (programming)|variable]]).
<syntaxhighlight lang="javascript">
functionvar sum = function() {
var i, x = 0;
for (i = 0; i < arguments.length; ++i) {