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
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
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.