On the default value of js function

Why do the following two writing methods produce two different results? Ask the boss for a detailed answer. Personally, I think it is related to the block-level scope of function parameters. But it"s still weird to understand, and it"s weird to look at it with chrome debugger. Why is the last input x output based on Block? Thank you very much ~

function test (x, y = function t () { x = 2 }) {
  // var x
  y()
  console.log(x) // 2
}
debugger
test()
Apr.08,2022
Menu