Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
Why reassigning const producing error in console only if we do that in code editor?

I wrote the following code in code editor to produce error:

const a = 1;
console.log(a);

const a = 1;  // Uncaught SyntaxError: Identifier 'a' has already been declared

I did the same thing directly into console --

const a = 1; //undefined
const a = 1; //undefined
const a = 2; // undefined
a // 2

Why here error was not caught?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Assuming you're using Chrome, this is by design. const redeclarations was intentionally implemented in Chrome Devtools 92 as a means to make it easier for developers to test code within the Chrome console:

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.

- Chrome Developer Blog

As the blog post points out, it enables you to redeclare const and other bindings you wouldn't usually be able to redeclare. This means something like:

> const a = 1;
> const a = 2;

is allowed as the two lines of code are executing in separate REPL scripts (indicated by the >), whereas performing:

> const a = 1;
  const a = 2;
x Uncaught SyntaxError: Identifier 'a' has already been declared

is not allowed as this is redeclaring const within the one REPL script (multiple lines of code can be entered into the one command line using SHIFT + ENTER). This change is only for the Chrome devtools console, and not for regular page scripts, which will throw a SyntaxError as expected if you try and redeclare const.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda