Web Development Articles

Page 530 of 801

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

What does the exclamation mark do before the function in JavaScript?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 3K+ Views

The exclamation mark (!) before a function in JavaScript is used to create an Immediately Invoked Function Expression (IIFE). It transforms a function declaration into an expression that can be executed immediately. How It Works The ! operator has lower precedence than the parentheses (), so the function executes first, then the ! operator applies to its return value: !function() { console.log("IIFE executed!"); }(); IIFE executed! Return Value Behavior Since functions return undefined by default, the ! operator converts this to true: let result1 ...

Read More

How to add number of days to JavaScript Date?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 19K+ Views

In this tutorial, we will learn how to add a number of days to a JavaScript Date object. Here we will discuss two methods which are following. Using the setDate( ) Method Using the getTime() Method Using the setDate( ) Method JavaScript date setDate() method sets the day of the month for a specified date according to local time. Syntax Date.setDate(dayValue) Here dayValue is an integer from 1 to 31, representing the day of the month. Approach To add a number of ...

Read More

How to use variable number of arguments to function in JavaScript?

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 728 Views

In JavaScript, functions can accept a variable number of arguments using the arguments object or modern rest parameters (...args). The arguments object contains all arguments passed to a function, regardless of how many parameters are defined. Using the arguments Object The arguments object is an array-like object that contains all arguments passed to a function: function functionArgument(val1, val2, val3) { var res = ...

Read More

How to Scroll to the top of the page using JavaScript/ jQuery?

Anjana
Anjana
Updated on 15-Mar-2026 330 Views

Scrolling to the top of a page is a common user experience feature that improves navigation, especially on long pages. JavaScript and jQuery provide several methods to achieve smooth scrolling to the top. Using jQuery animate() Method The most popular approach uses jQuery's animate() method to create a smooth scrolling effect: body { height: 2000px; padding: 20px; } #scrollBtn { position: fixed; bottom: 20px; right: 20px; padding: ...

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

What is the JavaScript version of sleep()?

Alankritha Ammu
Alankritha Ammu
Updated on 15-Mar-2026 483 Views

JavaScript doesn't have a built-in sleep() function like other languages, but you can create one using Promise and setTimeout() with async/await. Creating a Sleep Function The most common approach is to create a promise-based sleep function that works with async/await: function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async function displayMessages() { document.write('Wait for 3 seconds!'); await sleep(3000); document.write('After 3 seconds!'); document.write('Wait for 2 ...

Read More

Why do we use a plus sign in front of function name in JavaScript?

Anjana
Anjana
Updated on 15-Mar-2026 389 Views

The +function() {} notation is primarily used to force the parser to treat whatever follows the + as an expression. This is commonly used for Immediately Invoked Function Expressions (IIFEs). The Problem Without + Without the plus sign, JavaScript interprets a function declaration, which cannot be immediately invoked: // This causes a syntax error function() { console.log("Demo!"); }(); Using + to Create an IIFE The + operator converts the function declaration into an expression, allowing immediate invocation: IIFE with Plus Sign ...

Read More

What is the difference between getter and setter in JavaScript?

Akshaya Akki
Akshaya Akki
Updated on 15-Mar-2026 1K+ Views

In JavaScript, getters and setters are special methods that allow you to define how properties are accessed and modified in objects. They provide a way to control property access while maintaining a clean interface. Getter A getter is a method that gets executed when a property is accessed. It uses the get keyword and allows you to define custom logic for retrieving a property value. The getter appears as a regular property but internally calls a function. Setter A setter is a method that gets executed when a property is assigned a value. It uses the ...

Read More
Showing 5291–5300 of 8,010 articles
« Prev 1 528 529 530 531 532 801 Next »
Advertisements