Shubham Vora

Shubham Vora

793 Articles Published

Articles by Shubham Vora

Page 32 of 80

How to use unlimited arguments in a JavaScript function?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

In JavaScript, functions typically accept a fixed number of parameters, but there are several ways to handle an unlimited number of arguments. This tutorial explores three methods to pass and process multiple arguments in JavaScript functions. Using ES5 Arguments Object The arguments object is available in all non-arrow functions and contains all arguments passed to the function, regardless of how many parameters are defined. Syntax function functionName(param1, param2) { var actualParams = functionName.length; // Number of defined parameters var totalArgs = arguments.length; ...

Read More

How can I declare optional function parameters in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 11K+ Views

This tutorial will teach us how to declare optional function parameters in JavaScript. While declaring the function, we pass some variables to the function definition to use it inside the function block, called function parameters. The function parameters can also be optional, which gives us the independence to pass function arguments when we call the function. Here, Arguments are the values we pass while calling the function, and parameters are the variables we pass in the function definition. What Are Optional Parameters? The optional parameter word means that you don't need to pass that parameter every time ...

Read More

How to encode a URL using JavaScript function?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

As we know, a URL is a web address. What is URL encoding and why do we need to encode a URL? The process of turning a string into an accurate URL format is known as URL encoding. A valid URL format only uses "alpha | digit | safe | extra | escape" characters. Only a limited selection of the normal 128 ASCII characters is permitted in URLs. Reserved characters that are not part of this set must be encoded. URL encoding increases the reliability and security of URLs. Each character that needs to be URL-encoded is encoded ...

Read More

How to decode a URL using JavaScript function?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 1K+ Views

In this tutorial, we will learn how to decode a URL using JavaScript. URL is an abbreviation for Uniform Resource Locator. A URL is the address of a certain Web site. Each valid URL, in principle, links to a different resource. These resources include an HTML page, a CSS document, a picture, etc. URL encoding refers to replacing certain characters in a URL with one or more character triplets composed of the percent character "%" followed by two hexadecimal numbers. The triplet's two hexadecimal digits represent the numeric value of the replacement character. URL encoding's reverse process is ...

Read More

How do I call a JavaScript function on page load?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 63K+ Views

This tutorial will teach us to call a JavaScript function on page load. In many cases, while programming with HTML and JavaScript, programmers need to call a function while loading the web page or after the web page load finishes. For example, programmers need to show the welcome message to the user on page load. There are various ways to call a function on page load or after page load in JavaScript, and we will look at them one by one in this tutorial. Using the onload event in the tag ...

Read More

How to execute a JavaScript function when I have its name as a string?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

Calling a function from a string stored in a variable can be done in multiple ways in JavaScript. The most common approaches are using the window object (for global functions), object property access, and the eval() function (though not recommended). This tutorial will guide you through different methods to execute a JavaScript function using its name as a string. Using the window Object Method The window object contains all global functions and variables. You can access any global function by treating the function name as a property of the window object. Syntax var functionName ...

Read More

How to check if a JavaScript function is defined?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 15K+ Views

In this tutorial, we will learn to check whether a JavaScript function is defined before calling it. If you call an undefined function, JavaScript throws a ReferenceError with the message "function is not defined." To avoid this error, you can check whether the function exists before calling it. We'll explore three different approaches to accomplish this. Using the typeof Operator The typeof operator returns the data type of a variable or function. When used with a function name, it returns 'function' if the function is defined, or 'undefined' if it's not. Syntax let isFunction ...

Read More

How do you find out the caller function in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 9K+ Views

In this tutorial, we will learn to find out the caller function in JavaScript. The function is the reusable code, and users can call it from anywhere. But sometimes, they need to know who is the caller function to perform some operation. For example, suppose that we can call any single function from another 2 to 3 functions, and we need to perform some operation according to the caller function. Users can understand this scenario by the below code example. function func3() { if (caller is func2()) { ...

Read More

How do I declare a namespace in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 6K+ Views

A namespace is a programming concept that gives identifiers (names of types, functions, variables, etc.) scope to avoid name conflicts. JavaScript doesn't have built-in namespace support, but we can simulate namespaces using objects to organize code and prevent variable name collisions. In modern web applications that use multiple libraries and components, namespaces help avoid confusion and conflicts in code. This tutorial covers how to implement namespaces in JavaScript using different approaches. Object Literal Notation The most common way to create namespaces in JavaScript is using Object Literal Notation. This approach creates a global object that contains all ...

Read More

How can I format numbers as dollars currency string in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 16K+ Views

This tutorial teaches us to format numbers as a dollar currency string in JavaScript. Now, the question arises that why we need to format the numbers as a dollar currency string? Well, the answer is here. Users can think about the scenario where they are developing an eCommerce website or application and must show product prices to the customers. What if they render product prices like 2500 and $2500? The second one looks better as '$' represents the USD currency and is the standardized way to show off the USD currency. Also, second approach is more understandable. Below, we ...

Read More
Showing 311–320 of 793 articles
« Prev 1 30 31 32 33 34 80 Next »
Advertisements