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
  • 14,183
  • 17
  • 67
  • 103

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
  • 174,988
  • 54
  • 320
  • 367
4

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

Barmar
  • 741,623
  • 53
  • 500
  • 612