Transcription of FUNCTIONS - nostarch.com
{{id}} {{{paragraph}}}
2 FUNCTIONSWe have alreadyusedseveral FUNCTIONS in the previouschapter things such asalertandprint to order themachine to perform a specific operation. In this chap-ter, we will startcreatingour own FUNCTIONS , making itpossible to extend the vocabulary that we have avail-able. In a way, this resembles defining our own wordsinside a story we are writing to increase our expressive-ness. Although such a thing is considered rather badstyle in prose, in programming it is Anatomy of a Function DefinitionIn its most basic form, a function definition looks like this:functionsquare(x) {return x*x;}square(12); 144 Eloquent javascript 2011 by Marijn HaverbekeHere,squareisthe name of the the name of its (first andonly) x*x;is the body of the keywordfunctionis always used when creating a new function.
JavaScript, fortunately, is from a generation of languages that solve this problem by going out of their way to preserve the local variable as long as it is in any way reachable.
Domain:
Source:
Link to this page:
Please notify us if you found a problem with this document:
{{id}} {{{paragraph}}}