Wednesday, July 3, 2024
HomeLanguagesJavascriptJavaScript Function displayName Property

JavaScript Function displayName Property

The Function.displayName property in JavaScript is used to set the display name of the function. If the displayName property is used to log the name without setting the displayName property of the function then the output will be undefined.

Syntax:

function.displayName = name

Return Value: It returns nothing instead, it sets the display name of the function.

Note: By default, the display name of the function is undefined.

Example: Below is the basic example of Function.displayName property.

javascript




function func1() { }
func1.displayName = "someName"
console.log(func1.displayName)


Output:

someName 

A few examples are given below for a better understanding of the function.displayName property.

Example 1: In this example, we will see the basic use of the function.displayName property.

Javascript




// Creating function name func1
function func1() {
 
    // Logging to console
    console.log("This is from function 1")
}
 
// Changing the func1 name to function1
// using the function.displayname
func1.displayName = "function1"
console.log("Display name of the function"
    + " func1 is :", func1.displayName)


Output:

Display name of the function func1 is : function1

Example 2: In this example, we will see the basic use of the function.displayName property.

Javascript




// Creating function name func
function func() { }
 
// Changing the func name to function1
// using the func.displayname
func.displayName = "function1"
console.log("function is :", func)
 
// Logging name of the function
// using function.name property
console.log("Name of the function "
    + "func is :", func.name)
console.log("DisplayName of the "
    + "function func is :",
    func.displayName)


Output:

function is : ƒ func() { }
Name of the function func is : func
DisplayName of the function func is : function1

We have a complete list of Javascript Function properties, to check those please go through this Javascript Function Complete reference article.

Browsers Supported:

  • Google Chrome
  • Mozilla Firefox

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha Wardslaus
Dominic Rubhabha Wardslaushttps://neveropen.dev
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments