Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!