I recently saw href='javascript:;'
. What's the difference between:
<a href='javascript:;'
vs:
<a href='javascript:void(0);'
When to use first one, and when to use second?
I recently saw href='javascript:;'
. What's the difference between:
<a href='javascript:;'
vs:
<a href='javascript:void(0);'
When to use first one, and when to use second?
One is a JavaScript program with no statements which resolves as undefined, the other uses void
to explicitly resolve as undefined. There is little to choose between them.
Never use either.
Only use a link if you are going to link to somewhere.
If you want a UI control that people can click on to trigger some JavaScript, use a <button type="button">
.
There is no practical difference. Both result in the expression evaluating to undefined
.
void
/ void()
is just a shortcut to get to undefined
, as is an empty expression terminating with an immediate semicolon.