0

Possible Duplicate:
what is the point of void in javascript

At many places I have seen Javascript Void, but I am still not able to understand why this one is used. I am able to do complex javascript coding but not clear about this particular function.

Community
  • 1
  • 1

1 Answers1

0

void is an operator that is used to return a null value so the browser will not be able to load a new page.

//explain the code

<a href="JavaScript:void(0);" ondblclick="alert('Well done!')">Double Click Me!</a>

In above ex nothing will happen on single click but if you double click it alerts Well done! (void(0) used to prevent the page from loading)

Sanket R. Patil
  • 181
  • 1
  • 8
  • Not a `null` value. It's an `undefined` value. Reloading the page won't happen magically, you're missing some explanation. – Rob W Jul 31 '12 at 09:33
  • Even though both are considered falsy values `null == undefined`, they're still [different things](http://jsfiddle.net/sqUdN/) `null !== undefined`. [As you can see](http://jsfiddle.net/zeaEW/), the [void](https://developer.mozilla.org/en/JavaScript/Reference/Operators/void) operator returns `undefined`, not `null`. – Fabrício Matté Jul 31 '12 at 10:07
  • Thank you all, now I understood! Thanks for your help. – user1565253 Aug 10 '12 at 12:36