Answers for "11.2. Anonymous Functions¶"

0

11.2. Anonymous Functions¶

function myFunction(parameter1, parameter2,..., parameterN) {

   // function body

}

/*A function defined in this way is a named function 
(myFunction, in the example above).

Many programming languages, including JavaScript, allow us to create 
anonymous functions, which do not have names. We can create an anonymous
function by simply leaving off the function name when defining it:*/

function (parameter1, parameter2,..., parameterN) {

   // function body

}
Posted by: Guest on July-07-2021
0

11.2.1. Anonymous Function Variables

/*Anonymous functions are often assigned to variables when they are 
created, which allows them to be called using the variable's name.

Let's create and use a simple anonymous function that returns the sum
of two numbers*/

let add = function(a, b) {
   return a + b;
};

console.log(add(1, 1));

//2

/*The variable add refers to the anonymous function created on lines
1 through 3. We call the function using the variable name, since the 
function doesn't have a name.*/
Posted by: Guest on July-07-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language