As a frontend developer or even as a backend developer maybe you have found
<a>) and you wondered what that means.
In this article, we will try to provide an explanation for the above syntax in order for you to know when and why it’s used. To do that we will have to take it element by element.
As in other programming languages,
For example, the following expression will return the value of the mathematical operation:
let sum = 1 + 1; console.log(sum); // 2
And the next expression will return
let sum = void(1 + 1); console.log(sum); // undefined
Even though the variable
(1 + 1):
let sum = void console.log(1 + 1); // 2 console.log(sum); // undefined
From the above, we can observe that the code that it is after the
void operator will always be executed but the return of the expression will always be
undefined. The role of
0 inside the void operator is simply just the one of a placeholder.
href attribute like mailto:, file:, tel:, sms: etc.
<a> tag will not send you to other web address. It will also not refresh the page as links usually do when you don’t specify a value for the href attribute.
If you are wondering why we don’t just remove the
href attribute, the answer is that by removing the
href attribute we will also remove the link appearance of the
<a> element. That means that the cursor will not change when hovering the
<a> tag. The cursor will act like it is on normal text.
In other words, by adding
The example link from the beginning of this article will run the
clickFunction function when the tag is clicked, but without refreshing the page or sending you to a different page.
When to use
In order to prevent the default behavior of a
<a> tag, it’s generally recommended to use the
<button> tag for buttons and the
<a> tag for links. Also, if you need or want to change the cursor, it’s recommended to use CSS instead of changing the tag to
In conclusion, we hope that now you have a better understanding of what