In this book Crockford considers void as the bad parts of Javascript. He mentions in his book that-
actually mean?
To understand the meaning or purpose of such a hyperlink, we should first understand the void operator.
What does void 0 mean?
The void operator evaluates the given expression and then returns undefined.
void (0)
void "abc"
void (new Date())
//all will return undefined
OK... got it...
But still it seems useless, isn't it!!!
I mean "What's the point of that?" More straightforward question is what's wrong with just using "undefined" itself?
Now to understand why people use void(x) instead of undefined, let us run the below code in IE8.
var undefined = "no longer undefined";
console.log(undefined) // outputs "no longer undefined"
However any environment that supports ECMAScript 5 or newer will have the undefined property of the global object as read-only, therefore this will not be a problem.
Now that we know what is the point of using void operator, let us move forward and understand the usability of this void with respect to the hyperlinks.
Sometimes, we may need to call some JavaScript from within a link. Normally, when we click a link, the browser loads a new page or refreshes the same page (depending on the URL specified). But we probably don't want this to happen if we've attached some JavaScript to that link.
When a browser follows a javascript: URI, it evaluates the code in the URI and then replaces the contents of the page with the returned value, unless the returned value is undefined. The void operator can be used to return undefined. If the result is undefined, then the browser stays on the same page.
To prevent the page from refreshing, we could use JavaScript:void(0).