This textbook is available atAmazon.com Logo
JavaScript: The Web Warrior Series 6th Edition

JavaScript: The Web Warrior Series (6th Edition)

Book Edition6th Edition
Author(s)Vodnik
ISBN9781305078444
PublisherCengage
SubjectComputer Science
Chapter 2, Working with Functions, Short Quiz, Exercise 1
Page 91

What is the difference between a named function and an anonymous function?

Explanation

The differences between the named and anonymous function are given below. 

Named FunctionAnonymous Function
The named function is assigned with a name.The anonymous function is a function with no name.
Named functions can be invoked from multiple places within the program.Anonymous functions can be used only in the place where it is written. It cannot be accessed from elsewhere within the program.

The syntax of a named function is given below.                                                                                  

function function_name(arguments) 

      //statements; 

}

The syntax of an anonymous function is given below.

function (arguments)

{

      //statements;

}

Sample Response

A named function can be used in multiple contexts whereas an anonymous function cannot be used.

How would you rate this answer and explanation?
Did you like this example?
Subscribe for full access
Page 91