为什么函数声明中的常量声明不会引发错误?

Why constant declaration in function declaration doesn't throw an error?

我正在从 MDN 学习,所以这里有这样的代码,令我震惊的是为什么 const choice = select.value; 行中的 choice 变量在这里用作常量。我相信 .value 可能会改变并且常量在赋值后不能改变......或者重新声明变量会导致错误...... 每次,我更改 select 值,它都会调用 setWeather 函数,对吗? 那么,下面发生了什么,有人可以解释一下吗?

const select = document.querySelector('select');
const para = document.querySelector('p');

select.addEventListener('change', setWeather);

function setWeather() {
  const choice = select.value;

  if (choice === 'sunny') {
    para.textContent = 'It is nice and sunny outside today. Wear shorts! Go to the beach, or the park, and get an ice cream.';
  } else if (choice === 'rainy') {
    para.textContent = 'Rain is falling outside; take a rain coat and an umbrella, and don\'t stay out for too long.';
  } else if (choice === 'snowing') {
    para.textContent = 'The snow is coming down — it is freezing! Best to stay in with a cup of hot chocolate, or go build a snowman.';
  } else if (choice === 'overcast') {
    para.textContent = 'It isn\'t raining, but the sky is grey and gloomy; it could turn any minute, so take a rain coat just in case.';
  } else {
    para.textContent = '';
  }
}

还有来自 MDN 网站的 link https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/conditionals

查看const变量的作用域,它的生命只存在于函数运行时,函数结束时结束,因此再次调用该函数时,它是一个新变量并被赋值。您必须了解变量的范围。

const 声明创建对值的只读引用。这并不意味着它持有的值是不可变的,只是变量标识符不能被重新分配。例如,在内容是对象的情况下,这意味着 对象的内容(例如,它的属性)可以更改 (有关详细信息,请访问:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const) .

请看下面的例子,就像 "const select" 一样,这里我声明了一个名为 "car" 的对象类型的常量变量,我可以改变 属性 "model" 的 "car" 个对象:

const car = {type:"Fiat", model:"500", color:"white"};
  car.model= "EX60";
  console.log(car);