0

I got an unexpected return value "undefined" from function 'fnExample1' if I indent code like this :

function fnExample1() {
  return
  1;
}

I have made this simple example : Example jsfiddle

Thanks.

Luca Zoffoli
  • 111
  • 3

1 Answers1

1

write return and 1 in one line

function fnExample1() {
  return 1;
}

The reason why your code returns undefined is javascript's "semicolon insertion", where a semicolon is inserted after return, and 1 is considered another statement (which is not executed)

gefei
  • 18,124
  • 7
  • 49
  • 65