I'm using some code to learn javascript OOP and it contains the following snippet that I'm trying to understand:
void window.setTimeout(function() {
$(".item").css("opacity", 1)
}, 400);
I've never used the void operator, and from the documentation, can't understand why it's used in this instance?
As you will have read, the void operator evaluates its operand and then results in the value undefined. When you call setTimeout, it returns a number (the timer handle). So void setTimeout(...) results in undefined instead of a number.
If the code is really as you've shown it, there's no purpose whatsoever to the void operator there, because the return value from setTimeout isn't being used for anything.
[I've removed the bit I wrote about CoffeeScript, as I couldn't create an example; the CoffeeScript compiler complained that void is a reserved word (which it is, but that's why I was using it). I don't do CoffeeScript, so figured best to just remove that.]
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