DEV Community

Cover image for Beyond Syntax: Exploring the Depths of JavaScript Functions

Beyond Syntax: Exploring the Depths of JavaScript Functions

Md Alfaz Hossain on January 05, 2024

Hello, developers today I will dive into the JavaScript functions. Let's start..... In JavaScript function is one kind of non-primitive data type....
Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited
const a = function(){
console.log("Hello Bangladesh")
}
a() // output is Hello Bangladesh
Enter fullscreen mode Exit fullscreen mode

In your example, a is not an anonymous function. It's correct to say that the value of the function expression (the function expression is the part on the right of the assignment) is an anonymous function, but the act of assigning this anonymous function to a variable in this way makes it cease to be anonymous - it will acquire the name of the variable.This can be verified by checking the function's name:

const a = function(){
console.log("Hello Bangladesh")
}
console.log(a.name). // 'a' - not an anonymous function, it has a name

console.log((function(){
console.log("Hello Bangladesh")
}).name)  // '' - no name - anonymous function 
Enter fullscreen mode Exit fullscreen mode

You can review your understanding of anonymous functions here: