0

I started learning JavaScript and I was doing some exercises. I got undefined in Mozilla console. I am just curious about whether or not I'm missing something. Here's what I did.

function myFunction () {
  console.log("test call");
}

myFunction();

Code showing undefined in the devtools console

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Post your code **here**, not as an image but as code. – Pointy May 01 '22 at 11:49
  • 1
    **DO NOT post images of code, data, error messages, etc.** - copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text. For more information please see the Meta FAQ entry [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) Please [edit] your question to include the text. – VLAZ May 01 '22 at 11:51
  • What exactly is the problem? – user17517503 May 01 '22 at 11:54
  • The code as posted doesn't have any `undefined` problems. The console will print `undefined` after most statements you type into it, because that's just what it does, and it's nothing to worry about. – Pointy May 01 '22 at 11:54

1 Answers1

0

To return a value other than the default, a function must have a return statement that specifies the value to return. A function without a return statement will return a default value. In the case of a constructor called with the new keyword, the default value is the value of its this parameter. For all other functions, the default return value is undefined.

Anton Marinenko
  • 2,749
  • 1
  • 10
  • 16