DEV Community

Discussion on: JavaScript functions

Collapse
 
jonrandy profile image
Jon Randy 🎖️

Your function stored in anonFunction is NOT anonymous. The act of assigning an anonymous function to a variable makes it acquire the name of that variable. This can be verified by checking the name property of the function:

// normal function
function test1() { return 0 }
console.log(test1.name)  // 'test1'

// anonymous function
console.log( (function () { return 0 }).name )  // <empty string>

// initially anonymous function stored in a variable
const test2 = function() { return 0 }
console.log(test2.name)  // 'test2' - no longer anonymous
Enter fullscreen mode Exit fullscreen mode