Javascript Articles

Page 512 of 534

How to find JavaScript function definition in Chrome?

Abhishek
Abhishek
Updated on 15-Mar-2026 7K+ Views

When developing or debugging web applications, finding JavaScript function definitions in Chrome is essential. Chrome provides multiple methods to locate functions quickly and efficiently. This tutorial covers three primary methods for finding JavaScript functions in Google Chrome: Using Developer Tools Sources Panel Using Inspect Element Using View Page Source Using Developer Tools Sources Panel The Developer Tools Sources panel is the most powerful method for finding and debugging JavaScript functions. Steps to Use Developer Tools Step 1: Open Developer Tools ...

Read More

What is the purpose of wrapping whole JavaScript files in anonymous functions?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 1K+ Views

The purpose of wrapping JavaScript files in anonymous functions is to create a namespace and control the visibility of member functions. It wraps the code inside a function scope and decreases clashing with other libraries. This is what we call Immediately Invoked Function Expression (IIFE) or Self Executing Anonymous Function. Syntax Here's the basic IIFE syntax: (function() { // code })(); As you can see above, the first pair of parentheses converts the code inside into an expression. The second pair of parentheses immediately calls the function that resulted from the ...

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

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
Showing 5111–5120 of 5,340 articles
« Prev 1 510 511 512 513 514 534 Next »
Advertisements