We often use code such as Javascript:void (0), so what does javascript:void (0) mean in JavaScript?
The key in Javascript:void (0) is the Void keyword, which is a very important keyword in JavaScript, which specifies that an expression is evaluated but does not return a value.
The syntax format is as follows:
<Head><Scripttype= "Text/javascript"><!--voidfunc () javascript:voidfunc () orvoid(func ()) javascript:void(func ())// -</Script></Head>
The following code creates a hyperlink, and nothing happens when the user clicks it.
<href= "javascript:void (0)"> Click here Nothing will happen </A >
void (0) evaluates to 0 when the user links, but does not have any effect on Javascript.
In the following example, a warning message is displayed after the user clicks the link:
<Head><Scripttype= "Text/javascript"><!--// -</Script></Head><Body><ahref= "javascript:void (alert (' Warning!!! ')")>Dot me!</a></Body>
The difference between href= "#" and href= "javascript:void (0)"
# contains a location information, the default anchor is #top that is the top of the page.
and javascript:void (0), only represents a dead link.
When the page is long, it uses # to locate the page in the format:# + ID.
If you want to define a dead link please use Javascript:void (0).
<ahref= "javascript:void (0);">Dot I'm not responding!</a><ahref= "#pos">Point me to the specified location!</a><BR>...<BR><PID= "POS">Trailing Anchor Point</P>
Javascript:void (0) meaning