Parameter variables are declared by default, so you can't declare them again with let or const, but why can you declare them with var?

under normal circumstances, variables declared by let or const cannot be declared repeatedly, and an error will be reported even when using var.
eg:

let a = 123;
var a = 456;

error prompt: Uncaught SyntaxError: Identifier "a"has already been declared

const C = 123;
var C = 456;

error prompt: Uncaught SyntaxError: Identifier "a"has already been declared

parameter variables are declared by default, so you cannot declare them again with let or const,

< H2 > but why can I use var declaration? What is the default declaration here? < / H2 >

eg:
use var to declare parameters within the function

function foo(x = 5, y = function() { x = 2; }) {
  var x = 3;
  y();
  console.log(x);
}
foo()     // 

use let to declare parameters within the function

function foo (x = 5, y = function () {x = 2;}) {

  let x = 3;
  y();
  console.log(x);
}
foo()     //  Uncaught SyntaxError: Identifier "x" has already been declared
Feb.27,2021
This is how the

Ecmascript standard is defined.


//
var a = "123";
var a = "321";

//
var a = "123";
let a = "321";

function foo(x = 5, y = function () { x = 2; }) {
    let x = 3;
    // y();
    console.log(x);
}
foo();

the result is the same even if the function is not called. Function argument variables are declared by default, so you cannot declare them again using let and const, which is similar to the first case.
for instructions on let and const, please refer to the extension of the function in Ruan Yifeng's es6

.
function foo(x = 5, y = function() { x = 2; }) {

  let x = 3;
  y();
  console.log(x);
}
foo() 

the error is reported here. I think it should be the promotion of the function declaration, so it should be that he has already registered an x because he has executed y (); first, and then when he executes let xdeclare 3, he will report an error. I don't know if I understand it correctly. The assignment of his x should be 5 2 and finally the error is reported in let x = 3.


I also saw this code in the function extension chapter of "introduction to ES6 Standard" by Ruan Yifeng today. I am also very confused. In the chapter, the author is talking about .png. I am even more confused about how it can be in different scope. I only remember now that whenever declares a parameter variable again with var, the variable declared by var and the parameter variable are not the same variable. To access the variable directly in the body of the function is to access the variable declared by var

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2b782-40024.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2b782-40024.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?