In this post, we'll learn what
void(0) means so the next time you see it, you'll understand what it means.
It's used to evaluate an expression without returning a value. It's also used to prevent the default action of an element.
This operator is mostly used in the
href attribute of an anchor tag.
It's used to prevent the browser from following the link. It's also used to prevent the browser from following the link when the link is clicked.
Let's look an example where you might see this:
When you click on that link, nothing will happen.
This is useful for when you want to create a link for SEO purpose, but not have it lead to a page.
On the other hand, here is an anchor link with an
alert function instead of
The browser will execute the code since it's not
When you click on that link, it will show an alert with the text "Hello World!".
In this post, we learned what
void(0) means and how it's used.
If you want a link to essentially do nothing, you can use
void(0) with the
Thanks for reading!
If you want to learn about web development, founding a start-up, bootstrapping a SaaS, and more, follow me on Twitter! You can also join the conversation over at our official Discord!
Leave us a message!