
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Named function expression in JavaScript
Following is the code to implement named function expression in JavaScript.
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; color: blueviolet; } </style> </head> <body> <h1>Named function expression in JavaScript.</h1> <div class="result"></div> <br /> <button class="Btn">CLICK HERE</button> <h3>Click on the above button to call the fact function expression of obj object</h3> <script> let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let obj = { fact: function factorial(n) { if (n <= 1) { return 1; } return n * factorial(n - 1); }, }; BtnEle.addEventListener("click", () => { resEle.innerHTML = obj.fact(5); }); </script> </body> </html>
Output
On clicking the ‘CLICK HERE’ button −
- Related Articles
- Function Expression vs Function Declaration in JavaScript?
- Named arguments in JavaScript.
- How do we use Python Regular Expression named groups?
- How to set named cookies in JavaScript?
- Default exports vs Named exports in JavaScript.
- How to define a JavaScript function using the expression?
- Named capture groups JavaScript Regular Expressions
- How to use named arguments in JavaScript functions?
- Regular Expression Matching in JavaScript
- What are sex hormones? Why are they named so? State their function.
- In JavaScript, what is meant by 'a function expression is always a constant value'?
- The yield* expression/keyword in JavaScript.
- Regex named groups in Java
- Named Arguments in PHP 8
- Named Arguments in Lua Programming

Advertisements