Articles on Trending Technologies

Technical articles with clear explanations and examples

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

How to call multiple JavaScript functions in onclick event?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 2K+ Views

To call multiple JavaScript functions in onclick event, you can separate them with semicolons. This allows you to execute several functions sequentially when a single click occurs. Syntax onclick="function1(); function2(); function3()" Method 1: Using Semicolons The simplest approach is to separate multiple function calls with semicolons directly in the onclick attribute: function Display1() { document.getElementById("output").innerHTML += "Hello there!"; } ...

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

What is the difference between a++ and ++a in JavaScript?

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 8K+ Views

In JavaScript, ++a (pre-increment) and a++ (post-increment) both increase a variable by 1, but they differ in when the increment happens and what value they return. Pre-increment (++a) ++a increments the variable first, then returns the new value. The ++ operator comes before the operand. Post-increment (a++) a++ returns the current value first, then increments the variable. The ++ operator comes after the operand. Example: Basic Difference let a ...

Read More

Which one is better to use for a JavaScript link, "#" or "javascript:void(0)"?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 255 Views

When creating JavaScript links that don't navigate to another page, developers often choose between "#" and "javascript:void(0)". Both prevent default navigation, but they behave differently and have distinct use cases. Understanding the Difference The "#" anchor creates a link to the top of the current page and adds a hash to the URL, while "javascript:void(0)" executes JavaScript that returns undefined, preventing any navigation without affecting the URL. Using "#" Hash Links The hash symbol creates an anchor link that jumps to the top of the page if no element with that ID exists: ...

Read More

How do I split a string, breaking at a particular character in JavaScript?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 280 Views

JavaScript's split() method breaks a string into an array at every occurrence of a specified character or substring. This is useful for parsing data, processing text, or formatting output. Syntax string.split(separator, limit) Parameters separator: The character or string to split on limit: (Optional) Maximum number of splits to make Basic Example Let's split a string at every tilde (~) character: String Split Example ...

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
Showing 19091–19100 of 61,297 articles
Advertisements