Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return void(0); vs return; interrupting functions [duplicate]

Tags:

javascript

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?

like image 918
Chris Bier Avatar asked Apr 19 '13 22:04

Chris Bier


2 Answers

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.

like image 183
zzzzBov Avatar answered Sep 21 '22 07:09

zzzzBov


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

like image 42
Barmar Avatar answered Sep 22 '22 07:09

Barmar