为什么语法分析器不会在回车后在var中插入分号,但是在函数t中却插入了返回?
var a = 5
+
5
console.log(a); //results 10
function t(){
return
5
}
console.log(t()); //results undefined
为什么语法分析器不会在回车后在var中插入分号,但是在函数t中却插入了返回?
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.