The Wayback Machine - https://web.archive.org/web/20240911003713/https://www.geeksforgeeks.org/what-does-javascriptvoid0-mean/
Open In App

What does javascript:void(0) mean?

Last Updated : 04 Jun, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In JavaScript, javascript:void(0) is a pseudo-URL that does nothing when clicked. It’s commonly used as a placeholder in href attributes to prevent the browser from navigating to a new page while still executing JavaScript code.

Using “#” in an anchor tag

When writing the following code in the editor, the web page is refreshed after the alert message is shown. 

Example: 

html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GeeksforGeeks</title>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>without JavaScript:void(0)</h3>
    <a href="#" ondblclick="alert('Welcome to Geeks for Geeks')">
        Double click on me
    </a>
    <a href="#" ondblclick="geeks()">
        Double click on me
    </a>
    <script>
        function geeks() {
            document.getElementById("gfg").innerHTML = 
            'Welcome to GeeksforGeeks';
        }
    </script>
    <p id="gfg"></p>
</body>

</html>

Output: 

What does javascript:void(0) mean?

What does javascript:void(0) mean?

Using “javascript:void(0);” in anchor tag

Writing “javascript:void(0);” in anchor tag can prevent the page to reload and JavaScript functions can be called on single or double clicks easily.

Example: 

html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, 
                   initial-scale=1.0">
    <title>GeeksforGeeks</title>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>JavaScript:void(0)</h3>
    <a href="javascript:void(0);" ondblclick="geek()">
        Double click on me
    </a>
    <p id="gfg"></p>
    <script>
        function geek() {
            document.getElementById("gfg").innerHTML = 
            "Welcome to GeeksforGeeks";
        }
    </script>
</body>

</html>

Output: 

What does javascript:void(0) mean?

What does javascript:void(0) mean?



Similar Reads

What is void and when to use void type in JavaScript ?
In this article, we will know what is void operator in Javascript, along with discussing the particular condition where void operator can be used &amp; understanding their implementation through the examples. The void keyword in JavaScript, is used to evaluate an expression which does not return any value. The void operator is an unary operator tha
5 min read
Which href value should we use for JavaScript links, "#" or "javascript:void(0)" ?
In this article, we will know which "href" should be used for JavaScript when we can use "#" or "javascript:void(0)". Let us understand it. Using the '#' value: The # is a fragment identifier used to refer to a specific section of the same document. When a user clicks a link with a # href, the browser will scroll to that section of the page specifi
3 min read
What is the use of the Void Operator in JavaScript ?
The void operator in JavaScript is like a special command that tells the computer to do something but not worry about what comes back. It's often used when you want to make a clickable link on a website that doesn't take you to a new page. Instead of saying "go nowhere," you use 'void(0)' in the link, and it makes sure nothing happens, keeping thin
1 min read
What does +_ operator mean in JavaScript ?
Unary Operator: A unary operation contain only one operand. Here, the '+' unary plus operator converts its operand to Number type. While it also acts as an arithmetic operator with two operands which returns an addition result on calculation. JavaScript Identifiers: Javascript Identifiers are used to name variables (and keywords, functions, and lab
2 min read
What does !== undefined mean in JavaScript ?
In JavaScript, !== is a strict inequality operator, and undefined is a special value representing the absence of a value or the lack of an assigned value to a variable. The !== operator checks for both value and type equality, and !== undefined is used to verify if a variable is not equal to the undefined value. Table of Content Using Strict Inequa
1 min read
What does "this" keyword mean in JavaScript ?
In JavaScript, the 'this' keyword stands as a identifier, bridging the gap between functions and their invoking context. This unique identifier grants functions the ability to interact with and manipulate the properties of the object that triggered their invocation, serving as a reference to the current instance or object in control of the ongoing
2 min read
What does enumerable property mean in JavaScript?
An enumerable property in JavaScript means that a property can be viewed if it is iterated using the for...in loop or Object.keys() method. All the properties which are created by simple assignment or property initializer are enumerable by default. Example 1: The code defines a student object with property registration, name, age, and marks. A for.
2 min read
ES6 Void Keyword
The void keyword in JavaScript ES6 is used to evaluate an expression and it does not return any value. It is a unary operator and takes a single operand. We commonly use it in hyperlinks. Sometimes, we may need to call some JavaScript from a link. When we click on a link, the browser loads a new page or refreshes the same page. But we don't want th
2 min read
Describe the void elements in HTML
Most of the HTML elements are surrounded by start and end tags to specify the starting and end of the element. There is a special group of elements that only have start tags and does not contain any content within it, these elements are called void elements. Void elements doesn't have ending tags and can only have attributes but do not contain any
3 min read
TypeScript Return type void
The void type in TypeScript represents the absence of a return value for functions. It indicates that a function does not return any value, ensuring that the function's purpose is solely to act without returning data. Syntaxfunction functionName(parameters: ParameterType): void { // Function body // No return statement or return type annotation is
3 min read
TypeScript void Function
Void functions in TypeScript are functions that do not return a value. They perform actions or computations without producing a result that needs to be captured. Commonly used for side effects like logging, modifying external state, or triggering asynchronous operations, they enhance code clarity. Syntax: function functionName(parameters: Parameter
3 min read
What is the difference between MEAN.js and MEAN.io?
MEAN (MongoDB, Express.js, AngularJS (or Angular), and Node.js) is a free and open-source software stack for building dynamic web sites and web applications. The acronym MEAN was given by Valeri Karpov when he introduced the term first time in a blog post in 2013. The framework uses JavaScript for both client and server-side interaction. The framew
3 min read
What does the “+” (plus sign) CSS selector mean?
The "+" sign selector is used to select the elements that are placed immediately after the specified element but not inside the particular elements. Note: The IE8 and earlier versions &lt;/DOCTYPE&gt; must be declared to work element + element selector. Syntax: element + element { // CSS property } Example: &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;he
1 min read
What does it mean to start a PHP function with an ampersand?
An ampersand just before the function name will return a reference to the variable instead of returning its value. Returning by reference is useful when you want to use a function to find to which variable a reference should be bound. Do not use return-by-reference to increase performance. In PHP 4, objects were assigned by value, just like any oth
2 min read
What does the mean of pipe (|) symbol in Typescript ?
In Typescript, pipe(|) is referred to as a union type or "Or". it is also called union type in typescript. A value that can be any of numerous kinds is described by a union type. Each type is separated by a pipe (|), thus the number| string represents a value whose type can be a string or a number. or we can say either of the specified types is per
3 min read
What does enctype='multipart/form-data' mean in an html form ?
When building a web application, it's common to include forms that allow users to submit information. HTML forms can be used to send data to a server for processing, but it's important to specify the encoding type of the form. The enctype attribute is used to specify the encoding type of an HTML form. The enctype attribute specifies how the form da
3 min read
What does &lt;%= mean in EJS Template Engine ?
EJS or Embedded Javascript Templating is a templating engine used by Node.js. Template engine helps to create an HTML template with minimal code. Also, it can inject data into an HTML template on the client side and produce the final HTML. EJS is a simple templating language that is used to generate HTML markup with plain JavaScript. It also helps
3 min read
What does it mean for a component to be mounted in ReactJS ?
For a component to be mounted in ReactJS it means to be initialized and inserted in the DOM. Mounting is the initial phase in which the instance of the component is created and inserted into the DOM. When the component gets successfully inserted into the DOM, the component is said to be mounted. In the updating phase, the component gets updated whi
2 min read
Javascript Program for Mean of range in array
Given an array of n integers. You are given q queries. Write a program to print the floor value of mean in range l to r for each query in a new line. Examples : Input : arr[] = {1, 2, 3, 4, 5} q = 3 0 2 1 3 0 4 Output : 2 3 3 Here for 0 to 2 (1 + 2 + 3) / 3 = 2 Input : arr[] = {6, 7, 8, 10} q = 2 0 3 1 2 Output : 7 7Recommended: Please solve it on
3 min read
JavaScript Program to Find Geometric mean in G.P.
The geometric mean in a geometric progression (G.P.) is computed as the nth root of the product of all terms, where n is the number of terms. It provides a measure of central tendency in exponential sequences. This calculation is crucial in various mathematical and statistical analyses and we will see multiple approaches to do so. If there are n el
2 min read
What Do Multiple Arrow Functions Mean in JavaScript?
In JavaScript, arrow functions provide a concise syntax for writing function expressions. When you use multiple arrow functions in sequence, it typically signifies a series of nested functions, often used for currying or higher-order functions. These are the following methods to show the multiple arrow functions in JavaScript having different uses:
2 min read
Finding Mean at Every Point in JavaScript Array
We have given the array of numbers and our task is to find the mean at every position in the array using JavaScript. Below we have added the example for a better understanding of the problem statement. Example:Input: arr = [1, 2, 3, 4, 5]Output: Mean at position 1: 1Mean at position 2: 1.5Mean at position 3: 2Mean at position 4: 2.5Mean at position
4 min read
How does internationalization work in JavaScript?
Internationalization (also referred to as i18n) is that the method of making or reworking product and services so they'll simply be tailored to specific native languages and cultures. Localization (also referred to as L10n) is that the method of adapting internationalized computer code for a particular region or language. In alternative words, inte
3 min read
What does the leading semicolon in JavaScript libraries do ?
Semicolons in JavaScript divide the community. Some developers prefer to use them always. Few developers want to avoid them. In some cases, omitting them may lead to bad consequences. A semicolon is required When two statements are on the same line. So if you’re going to put two statements on the same line, you have to separate them with a semicolo
3 min read
Does JavaScript have higher precedence than CSS ?
While working on the front-end part of your project, CSS plays a major role in defining the styles for your web page. With the help of knowledge in DOM (Document Object Model) and JavaScript, it is possible to change styles for your web page using script files. In this article, we will discuss the precedence of JavaScript with respect to CSS in ter
2 min read
How to filter values from an array for which the comparator function does not return true in JavaScript ?
The task is to filter the array based on the returned value when passed to the given function. The purpose is to loop through the array and execute one function that will return true or false. Then filter out all the values for which the function (comparator function) does not return true. These are the following methods for filtering the values fr
3 min read
How does Implicit coercion differs from Explicit coercion in JavaScript ?
Coercion refers to the process of automatic or implicit conversion of values from one data type to another. This includes conversion from Number to String, String to Number, Boolean to Number, etc. when different types of operators are applied to the values. There are two types of coercion, Implicit coercion and explicit coercion: 1. Implicit coerc
3 min read
How does asynchronous code work in JavaScript ?
In this article, we will learn about asynchronous code working in JavaScript. Let us understand the basic details which are associated with Synchronous JavaScript. Synchronous JavaScript: Synchronous JavaScript implies that the user is having the data which is synchronously accessed as well as available in order.In this, the user tries to access th
3 min read
How does JavaScript .prototype work ?
In JavaScript when adding behaviour to objects, then if creating multiple objects using the constructor (calling the constructor function with the 'new' keyword) then the new keyword is the one that is converting the function call into constructor call and every time a brand new empty object is created which create inconsistency because for each ob
4 min read
How does TypeScript support optional parameters in function as every parameter is optional for a function in JavaScript ?
Optional parameters are those parameters whose value may or may not be provided as an argument during the function call. Their value is set to undefined when they are not provided as an argument. It is different from a default parameter for which we need to provide a default value at the time of defining the function. This default value is used in
4 min read