What Exactly Is “void 0” – And What’s It For?
Right. According to Tech-Faq, this is a fairly unique error, primarily because it can be encountered by users of pretty much any operating system.
There are quite a few issues which might cause this troublesome little error prompt to pop up:
- Conflicts with ad blockers/popup blockers
- An Outdated Web Browser
- Use of a proxy server
As I’m certain you’ve noticed, the error is caused by the user in all but the second case, where it’s usually caused by “web page authors who don’t check their script for compatibility.” In that circumstance, the user has no choice but to use the browser that the script was written for.
If you’re a developer or sysadmin, this is a reminder to test your scripts in as many browsers as possible.
And now for something completely different…with a very similar name.
The “void” Operator and “void 0”
“void” is an operator that can be applied to any argument in a script. The syntax goes a little something like this:
When “void(0)” is applied to an expression or argument, the value returned is always “undefined”, regardless of the other values present. That may seem somewhat useless at first glance; and more than a little obtuse. After all, why not simply use “undefined” itself?
For that matter, why do you need any of this stuff at all?
A couple reasons. Let’s start by explaining why the “undefined” value is important in the first place. Believe it or not, there’s actually a ton of different reasons one might use it.
Why Use “void”?
What’s The Difference Between “void (0)” and “undefined”?
On the other hand, “void” always returns the value of “undefined”. As far as the difference between “void (0)” and…well “void” with any other characters; that’s kind of irrelevant. “void “dingleberries”” would work just as well as “void (0)” or “void 0”.
Image credit: Andreas