Has the lifting behavior changed between chrome 48 and 49?

if (true) {
  function test() {
    console.log(true);
  }
} else {
  function test() {
    console.log(false);
  }
}

test()

Chrome 48 (and node <5.9.1) logs false, chrome 49 (and firefox) log true. I think they are optimized without rising from a fake branch, but they can disrupt existing applications.
Which one is correct by specification?

+4
source share
1 answer

According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function , the ECMAScript standard is designed to declare re-hoist functions in block statements for conditional creation, which is what Chrome 49 seems to do.

ECMAScript 6, , undefined - , ( ) , (, -, Chrome 48), test();, - -JavaScript, .

+2

All Articles