Javascript Articles

Page 510 of 534

How to delay a JavaScript function call using JavaScript?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 97K+ Views

In this tutorial, we are going to learn how can we delay a function in JavaScript. Whenever we want to call a function after a specified amount of time than we use the delay function in JavaScript. To provide delay in JavaScript function we use a global window object named as setTimeout(). This function allows us to provide a specific delay before executing a function. The setTimeout() method mainly requires two arguments: the function which we need to execute with some delay and the time (in milliseconds) for which we want to delay the function. Syntax ...

Read More

How to use associative array/hashing in JavaScript?

Abhishek Kumar
Abhishek Kumar
Updated on 15-Mar-2026 675 Views

We use Object and Map classes to mimic the behavior of associative array/hashing in JavaScript. JavaScript doesn't provide an associative array built-in. The closest similar behavior we get is from the Map class in JavaScript. Let us look at them one by one. Object Class in JavaScript The object class allows us to create objects with name-value pairs. This is similar to hashing as the object knows which property is associated with what value. Syntax const obj = { name : "Abhishek", age : 22 } var name ...

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 to add a number of months to a date using JavaScript?

Paul Richard
Paul Richard
Updated on 15-Mar-2026 841 Views

To add a number of months to a date in JavaScript, you can use the setMonth() method combined with getMonth(). This approach automatically handles year transitions and varying month lengths. Basic Syntax date.setMonth(date.getMonth() + numberOfMonths); Example: Adding Months to Current Date var currentDate = new Date(); var monthsToAdd = 3; document.write("Original Date: ...

Read More

How to parse JSON object in JavaScript?

Vikyath Ram
Vikyath Ram
Updated on 15-Mar-2026 751 Views

JSON (JavaScript Object Notation) is a lightweight data format commonly used for data exchange. JavaScript provides the built-in JSON.parse() method to convert JSON strings into JavaScript objects. Syntax JSON.parse(text, reviver) Parameters text - The JSON string to parse reviver (optional) - A function that transforms the results Basic JSON Parsing Example // Simple JSON string let jsonString = '{"name": "John", "age": 30, "city": "New ...

Read More

How can I pass a parameter to a setTimeout() callback?

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 2K+ Views

To pass a parameter to setTimeout() callback, you can use additional arguments after the delay parameter or use anonymous functions with closures. Syntax setTimeout(functionName, milliseconds, arg1, arg2, arg3...) The following are the parameters: functionName − The function to be executed. milliseconds − The delay in milliseconds. arg1, arg2, arg3 − Arguments passed to the function. Method 1: Using Additional Arguments Pass parameters directly as additional arguments to setTimeout(): Submit ...

Read More

How to compare Python DateTime with Javascript DateTime?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 15-Mar-2026 959 Views

Both Python and JavaScript have unique ways of representing date and time data. To compare Python datetime objects with JavaScript Date objects, we must ensure that both are converted to a common format, such as ISO 8601 strings or Unix timestamps (milliseconds since epoch). The following are two major differences between Python datetime and JavaScript Date objects: Month Representation: JavaScript uses a 0-indexed month (0 for January, 11 for December), while Python uses a 1-indexed month (1 for January, 12 for December). Default Time Zone: Python defaults to UTC, ...

Read More

What is the syntax for leading bang! in JavaScript function?

Nancy Den
Nancy Den
Updated on 15-Mar-2026 232 Views

The leading bang (!) in JavaScript is used to immediately invoke anonymous functions. It converts the function declaration into a function expression, allowing immediate execution. Why Use Leading Bang? JavaScript requires function expressions (not declarations) to be immediately invoked. The ! operator forces the parser to treat the function as an expression. Syntax !function() { // code here }(); Example: Basic Usage !function() { console.log("Immediately invoked with bang!"); }(); Immediately invoked with bang! Alternative Operators Besides !, ...

Read More

How to determine if an argument is sent to the JavaScript function?

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

To determine if an argument is sent to a JavaScript function, you can use several approaches including default parameters, checking for undefined, or using the arguments object. Using Default Parameters Default parameters provide fallback values when arguments are not passed or are undefined: function display(arg1 = 'Tutorials', arg2 = 'Learning') { document.write(arg1 + ' ' + arg2 + ""); } ...

Read More
Showing 5091–5100 of 5,340 articles
« Prev 1 508 509 510 511 512 534 Next »
Advertisements