1

Possible Duplicate:
Is there a difference between a function with and without a return statement?

Are there differences between an empty function and a function that only returns nothing?

Empty function:

function a() {
}

Function that only returns nothing:

function b() {
    return;
}
Community
  • 1
  • 1
XP1
  • 6,910
  • 8
  • 54
  • 61
  • @user1689607 Thanks. I tried to search for "empty function". – XP1 Nov 30 '12 at 03:10
  • I searched before answering too, but did not find this one. Instead I had found [this one](http://stackoverflow.com/questions/5596404/return-false-the-same-as-return) which isn't the same. – Michael Berkowski Nov 30 '12 at 03:13

1 Answers1

6

No, the return is implied if omitted in the first one. Both of them return undefined.

// In the console:
a();
// undefined
b();
// undefined

To expand a little further, this isn't the same as returning null:

function c() {
    return null;
}

c();
// null (which is a value, albeit a null one)

// Because
a() === c();
// false
null === undefined;
// false
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • 2
    The `typeof` result has no bearing on this. `undefined` is as much of a value as `null`, and `null` is not an object even though `typeof` tells us it is. – I Hate Lazy Nov 30 '12 at 03:09