0

why the syntax parser wont inject a semicolon in var after carriage return but in function t the return got injected ?

var a = 5
+
5
console.log(a); //results 10

function t(){
 return
 5
}

console.log(t()); //results undefined
  • https://stackoverflow.com/questions/2846283/what-are-the-rules-for-javascripts-automatic-semicolon-insertion-asi – epascarello Apr 08 '20 at 19:16

1 Answers1

1

Expressions in JavaScript do not end at the end of the line. Thats where semicolons are important. return is a complete statement on its own and has automatic semicolon insertion.

Daniel A. White
  • 174,715
  • 42
  • 343
  • 413