(function () {
var x = 0;
const foo1 = function(a, b) { var x = 2; }
const foo2 = (a, b) => { var x = 3; }
foo1(); console.log(x); // prints 0
foo2(); console.log(x); // prints 0
})()
However, there is the difference in how the implicit semicolons are inserted:
const foo1 = function(a, b) { return a + b; }
(2, 3)
console.log(foo1) // prints 5
const foo2 = (a, b) => { return a + b; }
(2, 3)
console.log(foo2) // prints [Function: foo2]
haha, oh ASI - I was very confused by your example as I read this as if it was
> const foo1 = function(a, b) { return a + b; }
(2, 3)
> console.log(foo1) // prints 5
> const foo2 = (a, b) => { return a + b; }
(2, 3)
> console.log(foo2) // prints [Function: foo]
Even though it makes no sense for (2, 3) to be a result in those cases, that was just how I ended up reading it, and I was exceptionally confused about how the printed output could possibly happen.
A super nice example of how subtle differences can really change things though.
As a side note, ASI for JS is actually super easy to implement and the rules are actually really simple (leaving aside whether the feature itself is good :D ) as it's just "these specific statements can have a new line instead of a semicolon" - so in the parser instead of consume(semicolon) you can just do "semicolon or newline" (You can check the logic in JSC in https://github.com/WebKit/WebKit/blob/main/Source/JavaScript... - just look for autoSemicolon() or autoSemi() I can't recall off the top of my head)