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

229
Vistas
Missing initializer in const declaration in node js

I am writing mysql query and kept those records in variable, My requirement is to get access that variable in anywhere so declared it outside of route,but it is showing error like : SyntaxError: Missing initializer in const declaration

const totalQuery = "select name from users";
   
    const totalRecords;
    dbConn.query(totalQuery,function(err,rows)     {
        totalRecords = rows.length
      
    })
    console.log('::'+ totalRecords);
    process.exit();

Error:

SyntaxError: Missing initializer in const declaration
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Make it let instead of constas you are re-assigning the totalRecords variable

about 4 years ago · Juan Pablo Isaza Denunciar

0

In javascript, you can't assign value to 'const' later after it's declaration. You're bound to assign the value to const on the declaration line.

If you really need to declare the value some where later, then better go with 'let'

about 4 years ago · Juan Pablo Isaza Denunciar
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