Usually, when the user clicks a link on a page a new page loads, but this is not always the desired course of action. For example, when the user clicks a link on a page, you might want to update the value of a field in a form or the value of a variable. To prevent a page from reloading when a link is clicked, the void(0) function is used.
Click on the above link. Even though the code within it specifies to display a message in an alert box (and this action does take place), the page will reload automatically.
In the above example, a message is displayed in an alert box as intended and void(0) prevents the page from reloading.