GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Functions in JavaScript - GeeksforGeeks Functions in JavaScriptLast Updated : 17 Jun, 2026 Functions in JavaScript are reusable blocks of code designed to perform specific tasks. They allow you to organize, reuse, and modularize code. They can take inputs, perform actions, and return outputs. Understanding FunctionsIn functions, parameters are placeholders defined in the function, while arguments are the actual values you pass when calling the function. Example:
Default Parameters
Return Statement
Types of FunctionsHere are all the main types of functions in JavaScript: 1. Named FunctionA function that has its own name when declared. It’s easy to reuse and debug because the name shows up in error messages or stack traces.
2. Anonymous FunctionAn anonymous function is a function defined without an explicit name. It is commonly used as a callback or assigned to a variable.
3. Function ExpressionA function expression is a function created as part of an expression and assigned to a variable or passed to another function. It can be named or anonymous.
4. Arrow Function (ES6)A new way to write functions using the
5. Immediately Invoked Function Expression (IIFE)IIFE functions are executed immediately after their definition. They are often used to create isolated scopes.
6. Callback FunctionsA callback function is passed as an argument to another function and is executed after the completion of that function.
7. Constructor FunctionA special type of function used to create multiple objects with the same structure. It’s called with the
8. Async FunctionFunctions that handle asynchronous tasks. Declared with
9. Generator FunctionDeclared with an asterisk
10. Recursive FunctionA function that calls itself until a condition is met. Very useful for problems like factorial, Fibonacci, or tree traversals.
11. Higher-Order FunctionA function that either takes another function as a parameter or returns another function. These are common in JavaScript (e.g.,
12. Nested FunctionsFunctions defined within other functions are called nested functions. They have access to the variables of their parent function.
13. Pure FunctionsPure functions return the same output for the same inputs and do not produce side effects. They do not modify state outside their scope, such as modifying global variables, changing the state of objects passed as arguments, or performing I/O operations.
14. Rest Parameter FunctionUses the ... syntax to collect remaining arguments into an array. Useful when the number of arguments is unknown.
JavaScript Examples:The following JavaScript section contains a wide collection of JavaScript examples, read here: Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |