Thanks for the answers guys, makes sense to me.

On 10/01/2011 18:53, Lasse Reichstein wrote:
On Mon, 10 Jan 2011 18:48:29 +0100, Fran <m...@fran.ie> wrote:

Why does "void(any_input)" return "undefined" ?

As others have said, it's the way it's defined. "void" is an operator that takes
one operand and evaluates to "undefined".
Notice that the parentheses are not needed. "void 2+4" works just as well.

Why does "typeof void" throw an exception ?

Because "void" is an operator that takes one operand, just like "!". Not
giving it an operand is a syntax error, just as "typeof !" is.

What is "void" for or what use can I give to it ?

It gives you a way to discard the value of an expression.
That's rarely necessary, but I use it occasionally in bookmarklets.
It's also one of the ways you can create the "undefined" value if you
don't trust the global "undefined" variable (which can be overwritten).
There are other ways too, but none as simple.

I'm quite curious about this reserved word and I'd like to know more about it and if it has any interesting use.

Very few interesting uses. There is a reason you don't see it more often.

/L


--
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to