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

177
Vistas
Alternative to using magic string values like "N/A"

I have special values that I extracted into a constant to signify special cases like "not found" or "does not exist". I thought this would be pretty clean, but now I am regretting my decision because I have to import the constant everywhere, and I need to keep it synced across frontend and backend. What is the best way to redesign the below?

Backend:

const ISBN_NOT_FOUND = 'N/A';

...

function populateBookDetails(book) {
    book.author = ...
    book.description = ...
    if(canFindISBN(book)) book.isbn = findISBN(book);
    else book.isbn = ISBN_NOT_FOUND
}

//for frontend to use
res.send(populateBookDetails(book))

Frontend:

const ISBN_NOT_FOUND = 'N/A';

...

function getISBNTruncated() {
    if(book.ISBN == ISBN_NOT_FOUND) return 'not found';
    else return ...
}

function getISBNFull() {
    if(book.ISBN == ISBN_NOT_FOUND) return 'The ISBN for this book could not be found';
    else return ...
}
about 4 years ago · Santiago Trujillo
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