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

Chapter 3. The JavaScript Language: Loop... > The JavaScript Function Object

The JavaScript Function Object

Believe it or not, JavaScript can treat functions as data types—with the result that you can declare a function as a variable. You can do this with the JavaScript Function object.

Here’s an example showing how this works. In this case, I’ll create a function named adder that will take two operands, which I’ll name operand1 and operand2, add them, and return their sum. You can do that with a new Function object as follows. (Recall that you have to use the new keyword when creating a new object.)


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint