DEV Community

Discussion on: JavaScript Functions — Understanding The Basics

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

We are assigning a variable value to the anonymous function object in the example below.

It's important to point out that this action makes the function cease to be anonymous - it will acquire the name of the variable:

// True anonymous function - no name
console.log( (function() {}).name ) // empty string - anonymous

// Anonymous function assigned to a var
// now had a name, not anonymous
const myFunc = function() {}
console.log(myFunc.name) // 'myFunc' - not anonymous any more
Enter fullscreen mode Exit fullscreen mode

So, in your example, the variable name does not contain an anonymous function, rather a named one.

More on anonymous functions here: