Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 2: Javascript Primer > Using Functions

USING FUNCTIONS

Douglas Crockford, in his book JavaScript: the Good Parts calls, functions the “best thing about JavaScript.” He’s right. Once you truly understand them you’ll be certain to agree. The flexibility and power of JavaScript functions can’t be understated.

This is especially true when working with jQuery, a library that fully leverages the expressive power of JavaScript functions.

Basically defined, a function is a block that encapsulates a series of JavaScript statements. Functions can accept and return values. The following code sample shows a simple function statement that explicitly returns the value of a calculation.

image
function calc( x ){
  return x∗2;
}
console.log( calc( 10 ) )
20

Code snippet is from simple-function.txt


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint