<分区>
process.on('exit', function () {
console.log("Exiting normally")
})
process.on('uncaughtException', function (err) {
console.log("Caught - " + err)
})
[1,2,3,4,5].forEach(function(element) {
console.log("Loop " + element)
})
这打破了:
Caught - TypeError: Cannot read property 'forEach' of undefined
Exiting normally
而当我添加一个分号时,它起作用了:
process.on('exit', function () {
console.log("Exiting normally")
})
process.on('uncaughtException', function (err) {
console.log("Caught - " + err)
}); // Added semi colon here
[1,2,3,4,5].forEach(function(element) {
console.log("Loop " + element)
})
这是否意味着为了安全起见我应该在每个语句后使用分号?