2

I have been reading a bit about undefined and just started wondering that we see undefined when we declare a function in browser console.

Does calling a function always return a value? If we do not explicitly return a value, then by default undefined value is returned from a function.

That is to say, a function will always return a value. Always. Is that correct?

var aFunc = function(){
 console.log( "aFunc ran." );
}
aFunc() === undefined // true
Kayote
  • 14,579
  • 25
  • 85
  • 144

1 Answers1

3

Yes it always returns a value, if explicit one is not given, it returns undefined. This is same as you will write return undefined or just return.

Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112