9

I ran across some code that interrupts a function return void(0);.

I believe that is being used to return undefined but that can be done simply by writing return;.

Does return void(0); serve an additional purpose, or is this just two different ways to interrupt a function?

Chris Bier
  • 13,618
  • 17
  • 64
  • 100

2 Answers2

7

return void(0); doesn't do anything special. It simply returns undefined, albeit in a very silly way. It's probably a case of the original developer not understanding JavaScript fully.

zzzzBov
  • 167,057
  • 51
  • 314
  • 358
4

It's just another way to return undefined. See https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/void

Barmar
  • 669,327
  • 51
  • 454
  • 560