On Jun 9, 9:30 am, Anton Kovalyov <[email protected]> wrote:
> I used the void operator today in a case when I needed to call a function,
> discard its return value and then return undefined. I did that mostly to be
> able to omit curly braces in the one-line if statement (i personally think
> they are ugly, especially when used in a very small constructions; python
> thing):
[...]
> Now I am curious in other cases when void is useful (except for bookmarklets,
> of course). Do you know any?
I've also seen them in ternary operators, again to put code on a
single line. I don't like it, but it is used by some:
if (test) {
doStuff();
}
can be written:
test? doStuff() : void 0;
in this case the false option can be anything that does nothing, so
*void 0* could be reaplaced with *null* or *0* (which are shorter) or
anything that doesn't actually do something.
If brevity matters (it rarely does), then:
if (test) doStuff();
is less code and clearer.
--
Rob
--
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]