If my script executes a function that returns e.g. a huge object that I don’t want to use or store, is it better/faster/less memory intensive to call that function with the void operator? Or will it decrease the performance because the return value will just be overwritten?
void myFunc();
Just created a test:
The
voidoperator is only used to obtain theundefinedprimitive value; it can be useful when you run code injavascript:inline mode, because the page won’t get replaced by the return value (casted to string) if it’sundefined.Therefore, there’s no appreciable difference between these two constructs:
JavaScript will run both in a void’ish manner, because the former statement doesn’t use the return value either.
See also:
void