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:
http://jsperf.com/voidperf
The void
operator is only used to obtain the undefined
primitive value; it can be useful when you run code in javascript:
inline mode, because the page won't get replaced by the return value (casted to string) if it's undefined
.
Therefore, there's no appreciable difference between these two constructs:
getSuperBigResult();
void getSuperBigResult();
JavaScript will run both in a void'ish manner, because the former statement doesn't use the return value either.
See also: void
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With