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

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 return 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>
<html>
<body>
	
	<a href="javascript:void(0);" 
	ondblclick="alert('Welcome Jim')"> Double click on me </a>

</body>
</html>

Output:

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.

void(0)

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

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