?To be more precise void is an operator, just typeof. The parentheses are optional, just like you can write -1 or -(1), the same is true for void(0) or void 0, although white space is required when parentheses aren't there for void and typeof.

-Nicholas


_____________________________________________________
Nicholas C. Zakas
Twitter: @slicknet
Blog: http://www.nczonline.net/

-----Original Message----- From: Michael Haufe (TNO)
Sent: Monday, January 10, 2011 12:41 PM
To: The JSMentors JavaScript Discussion Group
Subject: [JSMentors] Re: "void" function ?

On Jan 10, 11:48 am, Fran <[email protected]> wrote:
Hi there,

I have a couple question:

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

Because void is an operator that always returns undefined for any
valid input

Why does "typeof void" throw an exception ?

Because void needs an argument. void is not a function in the normal
sense.

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

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


To add another use case where void can be useful:

var myValue = doSomeTest ? someValue    :
                       anotherTest  ? anotherValue :
                       void 0;   //otherwise I don't care, but I have
to put something here
                                    //for it to be valid syntax and I
don't want a dummy value

--
To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]
--
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to