ES6 Code:
let foo = 'outer'; function bar(func = x => foo){ let foo = 'inner'; console.log(func()); } bar();
The result is "external."
ES5 code compiled by Babel.js:
'use strict'; var foo = 'outer'; function bar() { var func = arguments.length <= 0 || arguments[0] === undefined ? function (x) { return foo; } : arguments[0]; var foo = 'inner'; console.log(func()); } bar();
The result is "external."
I do not know why they have a different result.
source share