On Mon, Jan 10, 2011 at 8:48 PM, Fran <[email protected]> wrote: > Hi there, > > I have a couple question: > > Why does "void(any_input)" return "undefined" ? >
Just because of such an algorithm. Thus, an expression is always evaluated. See http://sideshowbarker.github.com/es5-spec/#x11.4.2 > Why does "typeof void" throw an exception ? > typeof accepts also an expression, not an operator (void). > 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. > > I can't remind any useful case except one -- to get `undefined` value in ES3 in case if the `undefined` property of the global has been rewritten. E.g. var foo; undefined = true; if (foo == undefined) // doesn't pass if (foo == void(0)) // pass Though even this use-case is synthetic, since this check, first, can be replaced with checking typeof foo == "undefined", and second -- in ES5 it's fixed, `undefined` global property is not writable. Dmitry. -- 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]
