Skip to content

A href JavaScript void 0 (undefined primitive value) | Code

  • by

JavaScript void(0) is the simplest way to prevent the default behavior of a tag. Web Developers use javascript:void(0) in href to prevent the default behavior of <a> tag. void(anything) returns undefined and it is a falsy value. And returning a falsy value is like returning false in the onclick event of a tag that prevents its default behavior.

A href JavaScript void 0 Example

HTML example code will only work when the link will be clicked twice.

<!DOCTYPE html>
	<a href="javascript:void(0);" 
	ondblclick="alert('Welcome Jim')"> Double click on me </a>



A href JavaScript void 0 code

Q: What does “javascript:void(0)” mean?

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


The void operator evaluates given expressions and returns undefined.

Do comment if you have any doubts and suggestions on this JS href code.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.