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 — JavaScript Function Invocation - GeeksforGeeks JavaScript Function InvocationLast Updated : 11 Jul, 2025 In JavaScript, function invocation refers to executing the code defined in a function. Function invocation occurs when a function is called or executed in JavaScript. When invoked, the code inside the function block is run, and any return value is computed and passed back to the caller.
Output Hello, Meeta!
Types of Function InvocationJavaScript provides several ways to invoke functions. Each method affects the behavior of this (the execution context) and other factors. 1. Function InvocationWhen a function is called directly using its name, it operates in the global or local scope.
Output 8 Scope: In non-strict mode, this defaults to the global object (window in browsers). 2. Method InvocationWhen a function is a property of an object and is invoked as object.method(), it is called a method invocation.
Output Hello, Meeta! In method invocation, this refers to the object that owns the method (in this case, user). 3. Constructor InvocationFunctions can be invoked as constructors using the new keyword. When invoked this way, the function creates a new object and sets this to refer to that object.
Output Meeta A constructor invocation returns the newly created object. 4. Indirect InvocationFunctions can be invoked indirectly using call(), apply(), or bind(). call(): Invokes a function and explicitly sets this and individual arguments.
Output Hello, Meeta! apply(): Similar to call(), but arguments are passed as an array.
bind(): Creates a new function with this permanently set to the provided value.
Output Hey, Meeta! 5. Self-Invoking FunctionsSelf-invoking (or immediately invoked) functions run automatically without being explicitly called. These are often written as Immediately Invoked Function Expressions (IIFEs).
Output This is a self-invoking function! IIFEs are commonly used for encapsulating code to avoid polluting the global scope. 6. Arrow Function InvocationArrow functions are invoked like regular functions but differ in how they handle this. They do not bind their own this; instead, they inherit this from their lexical scope.
Output Hello, undefined! 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. |