Home >Web Front-end >JS Tutorial >Example analysis of the true meaning of javascript:void(0)_javascript skills
When you look at JavaScript scripts, you can often see code like this:
〈a href="javascript:doTest2();void(0);"〉here〈/a〉
But what exactly is void(0) here? What does it mean?
void is an operator in JavaScript, which specifies that an expression is to be evaluated but does not return a value.
void operator usage format is as follows:
1. javascript:void (expression)
2. javascript:void expression
expression is a JavaScript standard expression to be calculated . The parentheses outside the expression are optional, but it is a good practice to write them.
You can specify a hyperlink using the void operator. The expression is evaluated but nothing is loaded into the current document.
The following code creates a hyperlink that does nothing when the user clicks on it. When the user clicks the link, void(0) evaluates to 0, but has no effect on JavaScript.
The difference between void and #
# contains a location information. The default anchor point is #top, which is the top of the web page, while javascript:void(0) only represents a dead link.
This is why sometimes the browsing link on a very long page jumps to the top of the page even if it is #, but this is not the case with javascript:void(0), so it is best to use void(0) when calling the script.