-2
function aaa() {
  return
  {
    test: 1
  }
}

console.log(aaa());

Why this code result is undefined? I assume is will be object.

Dreams
  • 8,288
  • 10
  • 45
  • 71

1 Answers1

0

Because when you change the line it terminate the statement so you have to put curly bracket after return to make it work.

Just use this:

function aaa() {
  return {
    test: 1
  }
}

console.log(aaa());
anon
  • 855
  • 12
  • 22
Hemant Rajpoot
  • 683
  • 1
  • 11
  • 29
  • 2
    “Just use this” is not an answer to “Why this code result is undefined?”. – Sebastian Simon Nov 03 '17 at 04:18
  • Curious to know the difference between your code and OP's code. – Jigar Shah Nov 03 '17 at 04:19
  • becouse when you change the line it terminate the statment so you have to put curly braces after return to make it work if i helped then accept the answer – Hemant Rajpoot Nov 03 '17 at 04:24
  • i guess i have already tell the answer in my last comment – Hemant Rajpoot Nov 03 '17 at 05:26
  • 2
    @user2779185 It’d be better to [edit] your answer and include that comment, since that’s the explanation that is actually answering the question and that’s what’s missing in order to make your answer relevant. Though, this question unfortunately is a duplicate and as such already has an answer… – Sebastian Simon Nov 03 '17 at 05:42