Anchor tag onclick call JavaScript function | Example Code

First, you have to block href call URL if don’t want to open the tab/window or other operations. You can call a function in 2 ways using the href or onclick attribute in the HTML tag. Function inside href JavaScript link href=#” onclick Anchor tag onclick call JavaScript function Examples HTML example code: Or Output: Read More…


JavaScript function return value in new tab | Example Code

Create object of window.open() and then pass the function into document.write() method to pass JavaScript function value into a new tab. Open New Tab with Results from JavaScript function examples HTML example codes:- Add 2 number and pass to result into another tab Show String message into another tab using JS function Output: Do comment Read More…


Callback function with parameters JavaScript | Example code

You can pass some parameter to a function used as callback in JavaScript. These two options would look like this: Or Callback function with parameters in JavaScript Example HTML example code:- Using the arguments variable like so: Output: Read more: – JavaScript callback function Do comment on this topic if you have any doubts and Read More…


JavaScript access variable outside the callback | Example code

You can define the variable in function and pass it to callback function in JavaScript. The callback function should have a parameter option. Access to a variable outside of a callback function in javascript HTML example code:- Output: Do comment if you have any doubts and suggestion on this JS variable topic. RohitDegree in Computer Read More…


JavaScript sleep function | Make a function to pause execution for the time

First JavaScript doesn’t have inbuilt sleep functions instead You can use the setTimeout or setInterval functions. But you can make the custom sleep function in JavaScript. It will pause execution for a fixed amount of time. JavaScript sleep function Example Use this with the then callback: Use it in an Async function Complete example code: Read More…


JavaScript delay function | Simple example code

The window object allows the execution of code at specified time intervals. To delay a function call, you can use setTimeout() function. This function will Execute a function, after waiting for a specified number of milliseconds. JavaScript delay function Example code HTML example code where you have to click a button and wait 1 second Read More…


JavaScript run function after a delay | Simple example code

Use setTimeout() inbuilt function to run function after a delay in JavaScript. It’s plain JavaScript, this will call your_func once, after fixed seconds (time). 5000 = 5 sec If function has no parameters and no explicit receiver you can call directly setTimeout(func, 5000) JavaScript run function after a delay Example code HTML example code: Function Read More…


JavaScript function return multiple values | Use Array Example

Can function return multiple values in JavaScript? No, the JS function could not return multiple value returns but it could return an array containing multiple values or as properties of an object. Note: JavaScript functions can return only single value. JavaScript function return multiple values Example code Let’s see HTML example code for How to Read More…


JavaScript function with default parameter | Set Default Parameters example

Assign a default value to the parameter is called a function with the default parameter in JavaScript. A default value is required if no value or undefined is a passed-in function. JavaScript function with default parameter Example Let see HTML example code of How to set default parameters in JS function. Default value for b Read More…


JavaScript function optional parameter | 3 Ways Examples code

You can declare a function with optional parameter using Logical OR operator (‘||’) or Assignment operator (“=”), etc in JavaScript. JavaScript function optional parameter can do it in 3 ways:- Undefined property OR (||) operator The assignment operator (“=”) Declare optional function parameters in JavaScript Example Let’s see all method examples in HTML:- Using undefined Read More…