What is the purpose of JavaScript:void(0)?

Void(0) is used to prevent the page from refreshing. This will be helpful to eliminate the unwanted side-effect because it will return the undefined primitive value.

It is commonly used for HTML documents that use href=”JavaScript:void(0);” within an anchor element. i.e, when you click a link, the browser loads a new page or refreshes the same page. But this behavior will be prevented using this expression.

A javascript: URL will redirect the browser to a plain text version of the result of evaluating that JavaScript. But if the result is undefined, then the browser stays on the same page. void(0) is just a short and simple script that evaluates to undefined.

The following anchor tag does nothing and stays on the same page.

<a href="javascript:void(0);">DO IT NOW!</a>