0

Why can I redeclare the same constant with a new value? Online sources (w3s) say JavaScript const variables cannot be redeclared. Thank you for your time.

const myConst = 5;
a                       // Console outputs: 5 (Opera and Chrome)

const myConst = 7;
a                       // Console outputs: 7 (Opera and Chrome)
  • It's just a console oddity. When run in a normal context (outside the console), it'll throw as expected. – CertainPerformance Feb 04 '22 at 03:33
  • It's recently added feature for chrome that it's useful if you want to test some code in the console. Otherwise you have to refresh the page to test the code again since the variables are already declared. – Hao Wu Feb 04 '22 at 03:41

0 Answers0