Found 10711 Articles for Web Development

How to find JavaScript function definition in Chrome?

Abhishek
Updated on 31-Oct-2022 07:26:46

6K+ Views

In today’s time, almost everyone knows Google Chrome and how to use it for their comfort. But in the case of a developer, it is a must to have advanced knowledge of using Chrome because Chrome can help a developer tackle problems in many ways such as solving the problems or debugging the code with ease, inspecting the code, and finding JavaScript functions defined in the code. In this tutorial, we will learn how we can find a JavaScript function in Google Chrome that is defined in the JavaScript code. Here are three ways of finding the JavaScript function in ... Read More

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

Anvi Jain
Updated on 12-Jun-2020 08:58:55

745 Views

The purpose of wrapping is to 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.SyntaxHere’s the syntax −(function() {    // code })();As you can see above, the following pair of parentheses converts the code inside the parentheses into an expression −function(){...}In addition, the next pair, i.e. the second pair of parentheses continues the operation. It calls the function, which resulted from the expression above.

How do you find out the caller function in JavaScript?

Shubham Vora
Updated on 25-Jul-2022 08:35:18

6K+ 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() ) {       // code for some operation    } else if ( caller is func1() ){       // code for some different operation    } ... Read More

How do I declare a namespace in JavaScript?

Shubham Vora
Updated on 22-Jul-2022 12:22:55

3K+ Views

A namespace is a programming concept that gives identifiers (names of types, functions, variables, etc.) scope to avoid name conflicts. For instance, a program may need to use the same variable name in many contexts. In such a case, namespaces will separate these contexts so that the same identifier may be utilized in many namespaces.The initialization and application of namespaces in JavaScript will be covered in this tutorial. A namespace is not by default available in JavaScript. Constructing a global object that contains all functions and variables, the JavaScript Namespace feature may be repeated. Because numerous libraries and components are ... Read More

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

Rishi Rathor
Updated on 12-Jun-2020 08:46:17

2K+ Views

The ! symbol shows that it is an immediately-invoked function expression.The exclamation mark won’t invoke the function alone; you can put () at the end −!function foo() {}()() has higher precedence than ! and instantly calls the function.You can also mention it like the following −(function(){})();The ! allows the expression to return true. This is because by default all immediately-invoked function expression return undefined, so, we’re left with ! undefined, which is true.

How to add number of days to JavaScript Date?

Saurabh Jaiswal
Updated on 22-Aug-2022 08:21:05

18K+ 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 Its syntax is as follows − Date.setDate( dayValue ) Here dayValue is an integer from 1 to 31, representing the day of the month. Approach To add a number of days to the current date, first we ... Read More

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

Krantik Chavan
Updated on 07-Jan-2020 09:37:34

531 Views

To use a variable number of arguments to function, use the arguments object.ExampleYou can try to run the following code to implement arguments to a function in JavaScriptLive Demo                    function functionArgument(val1, val2, val3)  {             var res = "";             res += "Expected Arguments: " + functionArgument.length;             res += "";             res += "Current Arguments : " + arguments.length;             res += "";             res += "Each argument = "             for (p = 0; p < arguments.length; p++) {                res += "";                res += functionArgument.arguments[p];                res += " ";             }             document.write(res);          }          functionArgument(20, 50, 80, "Demo Text!","Hello World", new Date())          

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

Anjana
Updated on 16-Jun-2020 08:16:43

169 Views

ExampleLive Demo                    $("a").click(function() {             $("html, body").animate({ scrollTop: 0 }, "slow");             return false;          });             TOP OF PAGE             This is demo text.       This is demo text.       This is demo text.       This is demo text.       This is demo text.       This is demo text.       This is ... Read More

How to use setInterval function call in JavaScript?

Shubham Vora
Updated on 31-Oct-2022 11:44:51

2K+ Views

In this tutorial, we will learn how to use setInterval function call in JavaScript. The setInterval() method in JavaScript evaluates an expression at intervals. It is used to perform the repetitive tasks or operations that need to be performed in a specific time interval. For example, it calls a function repeatedly in a fixed time delay to perform the task. The window interface offers this method. This method returns an interval id that uniquely identifies the interval, allowing you to remove it later by executing the clearInterval() method. Users can follow the below syntax to use the setInterval function. Syntax ... Read More

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

Shubham Vora
Updated on 12-Jul-2022 12:35:55

15K+ 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 have given ... Read More

Advertisements