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

178
Visualizações
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 à 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