0

As I have learnt that we can not re-declare a const variable in JavaScript, but, in the console of Chrome, it allows us to redeclare whereas, in Firefox console or VS Code with Live Server extension in Chrome or Firefox shows the error. Why does re-declaring a const variable in Chrome console doesn't throw any Syntax Error?

Someone, please provide a good and clear explanation. Thank You.

enter image description hereChrome console

enter image description here

Firefox console

enter image description here

Code in VS Code with Live Server in Firefox

enter image description here

Code in VS Code with Live Server in Chrome

I tried it in different consoles and in VS Code and I observed that only in the console of the chrome, if we redeclare a const variable, it doesn't throw any error.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335

1 Answers1

3

The Console now supports redeclaration of const statement, in addition to the existing let and class redeclarations. The inability to redeclare was a common annoyance for web developers who use the Console to experiment with new JavaScript code.

https://developer.chrome.com/en/blog/new-in-devtools-92/#const-redeclaration

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335