Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

276
Vistas
Exception handling - Can't catch 'SyntaxError : Missing initializer in const declaration'

I learnt about hoisting in JavaScript , and wanted to experiment the kind of errors i could get , and to catch them. However i can't figure out how to catch this precise error:

SyntaxError : Missing initializer in const declaration.

Here is the piece of code:

try {
    g = 'Hello !';
    console.log(g);
    const g;
  } catch(err) {
    console.log('You got an error '+err);
  }
  console.log('rest of the code.')

I tested this try-catch with other exceptions, and everything seemed to work correctly. So I thought the problem was about hoisting and maybe variables were read right at the start of the block hence were not caught.

I tried to encapsulate the whole code in a try-catch but without any conclusive results. Here is my code encapsulated:

function hoisting() {
  try {
    g = 'Hello !';
    console.log(g);
    const g;
  } catch(err) {
    console.log('You got an error '+err);
  }
  console.log('rest of the code.');
}

function main() {
  try {
  hoisting();
  } catch(err) {
    console.log(err);
  }
}

main();
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda