Category: 4. JavaScript Functions
-
Smart Function Parameters
The concept of smart function parameters in JavaScript is a way to make a function adaptable to different use cases. It allows the function to handle the different kinds of arguments passed to it while invoking it. In JavaScript, the function is an important concept for reusing the code. In many situations, we need to ensure the…
-
Global Variables
JavaScript Global Variables The global variables in JavaScript are the variables that are defined outside of the function or any particular block. They are accessible from anywhere in JavaScript code. All scripts and functions can access the global variables. You can define the global variables using the var, let, or const keyword. The variables defined without using any of the var,…
-
Variable Scope
JavaScript Variable Scope The variable scope in JavaScript determines to the accessibility and visibility of the variable in different part of the code. The scope is the current context of the code execution. This means the variable scope is determined by where it is executed not by where it is declared. In JavaScript, the objects and functions are also…
-
Closures
What is Closure? The concept of closures in JavaScript allows nested functions to access variables defined in the scope of the parent function, even if the execution of the parent function is finished. In short, you can make global variables local or private using the closures. A JavaScript closure is basically a combination of the function and its lexical environment.…
-
Function bind() Method
Function bind() Method The function bind() method in JavaScript creates a new function with a specified this value and optional arguments, without invoking the original function immediately. It is commonly used to set the context (this) for a function and partially apply arguments. This method is used to bind a particular object to a common function. To understand the…
-
Function apply() Method
Function apply() Method The Function apply() method in JavaScript allows us to invoke a function given a specific value for this and arguments provided as an array. The Function call() and apply() methods are very similar, but the main difference between them is function apply() method takes a single array containing all function arguments, and the function call() method…
-
Function call() Method
Function call() Method The Function call() method allows us to invoke a function given a specific value for this and arguments provided individually. When a normal function is called, the value of this inside the function is the object that the function was accessed on. We can manipulate the this value and can assign an…
-
Function Invocation
Function Invocation The function invocation in JavaScript is the process of executing a function. A JavaScript function can be invoked using the function name followed by a pair of parentheses. When you write a function code in JavaScript, it defines the function with expressions and statements. Now, to evaluate these expressions, it is necessary to invoke the…
-
Arrow Functions
Arrow Functions The arrow functions in JavaScript allow us to create a shorter and anonymous function. Arrow functions are written without “function” keyword. The JavaScript arrow functions are introduced in ES6. Before ES6, we can define a JavaScript function with function declaration or function expression. The function expressions are used to define anonymous functions. The arrow functions allow us to write the function expressions…
-
Self-Invoking Functions
Self-Invoking Functions The self-invoking functions are JavaScript functions that execute immediately as they are defined. To define a self-invoking function, you can enclose an anonymous function within parentheses followed by another set of parentheses. These are also called self-executing anonymous functions. The anonymous function inside the first pair of parentheses is basically a function defined…