JavaScript:void(0)17 Mar 2025 | 2 min read The void operator is used to evaluate an expression and returns the undefined. Generally, this operator is used for obtaining the undefined primitive value. It is often used with hyperlinks. Usually the browser refreshes the page or loads a new page on clicking a link. The javascript:void(0) can be used when we don't want to refresh or load a new page in the browser on clicking a hyperlink. We can use the operand 0 in two ways that are void(0) or void 0. Both of the ways work the same. The JavaScript:void(0) tells the browser to "do nothing" i.e., prevents the browser from reloading or refreshing the page. It is useful when we insert links that have some important role on the webpage without any reloading. So, using void(0) on such links prevents the reloading of the page but allows to perform a useful function such as updating a value on the webpage. It is also used to prevent unwanted redirecting of the page. SyntaxLet's understand the use of javascript:void(0); using some examples. Example1In the following example, we are defining two links. In the first link, we are using the void keyword. When the corresponding link gets clicked, it will do nothing because of the void(0). When we click on the second link, it will display an alert dialog box. Output ![]() On clicking the first link, nothing will happen. When the user clicks the second link, the output will be - ![]() Now, in the next example, we will see how to prevent redirecting of the webpage. Example2In this example, we are passing the javascript:void(0); and link of the website to the href attribute. Here, we are also using the ondblclick attribute, which shows an alert box on double-clicking the hyperlink. On closing the alert dialog box, the page will not redirect to the specified link of the website. Output ![]() On double-clicking the specified link, the output will be - ![]() Next TopicjQuery vs. JavaScript |
A callback function can be defined as a function passed into another function as a parameter. Don't relate the callback with the keyword, as the callback is just a name of an argument that is passed to a function. In other words, we can say that...
3 min read
Redirect is nothing but a mechanism of sending search engines and users on a different URL from the original one. The redirected page can be on the same server or on a different server. It can also be on the same website or on different...
3 min read
? We will comprehend how to add a property to an object in JavaScript in this article. JavaScript Object The JavaScript object is a group of properties in the form of key-value pairs. Syntax: const obj = { property1: value1, property2: value2, property n: value3, }; ...
4 min read
The onscroll event in JavaScript occurs when a scrollbar is used for an element. The event is fired when the user moves the scrollbar up or down. We can use the CSS overflow property for creating a scrollbar. In HTML, we can use the onscroll attribute...
3 min read
JavaScript Scope What is Scope in JavaScript? In JavaScript, scope refers to the current context of our code in which variables are declared and can be accessed. In simple words, it helps us decide to define a variable or functions in JavaScript impacts where we can access...
5 min read
Object The object is the type of collection that allows us to store weakly held objects. Unlike Set, the WeakSet are the collections of objects only. It doesn't contain the arbitrary values. Syntax new WeakSet([iterable]) Parameter iterable - It represents the iterable object whose elements will be added...
1 min read
The object illustrates an array like view of an underlying binary data buffer. There are many number of different global properties, whose values are TypedArray constructors for specific element types, listed below. Types of TypedArray Int8Array Size in bytes: 1 Description: 8-bit two's compliment signed integer. Type: byte. Value Range:...
3 min read
In this tutorial, we will learn, discuss, and understand the JavaScript form. We will also see the implementation of the JavaScript form for different purposes. Here, we will learn the method to access the form, getting elements as the JavaScript form's value, and submitting the form. Introduction...
3 min read
The defer is a Boolean value, used to indicate that script is executed after the document has been parsed. It works only with external scripts (i.e., works only when we are specifying the src attribute in <script> tag). It declares that the script will not...
2 min read
Object The object is a type of collection which is almost similar to Map. It stores each element as a key-value pair where keys are weakly referenced. Here, the keys are objects and the values are arbitrary values. Syntax new WeakMap([iterable]) Parameter iterable - It represents an array...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India