patternjavascriptCritical
What does "javascript:void(0)" mean?
Viewed 0 times
voiddoesmeanwhatjavascript
Problem
login
I've seen such
hrefs many times, but I don't know what exactly that means.Solution
The
expression and then returns
The
to obtain the
value, usually using “
is equivalent to “
cases, the global variable
can be used instead (assuming it has
not been assigned to a non-default
value).
An explanation is provided here:
The reason you’d want to do this with the
void operator evaluates the givenexpression and then returns
undefined.The
void operator is often used merelyto obtain the
undefined primitivevalue, usually using “
void(0)” (whichis equivalent to “
void 0”). In thesecases, the global variable
undefinedcan be used instead (assuming it has
not been assigned to a non-default
value).
An explanation is provided here:
void operator.The reason you’d want to do this with the
href of a link is that normally, a javascript: URL will redirect the browser to a plain text version of the result of evaluating that JavaScript. But if the result is undefined, then the browser stays on the same page. void(0) is just a short and simple script that evaluates to undefined.Context
Stack Overflow Q#1291942, score: 1327
Revisions (0)
No revisions yet.