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

207
Views
What's the difference between a value of a database field being 'empty' and the field not existing? Are both not falsy?

I have the following problem:

const barcodeValue = element.dataset.barcode;

// the above value is sent as an argument to be verified by the function below..

if(!barcodeValue){

// run code

}

now dataset.barcode comes from the database... currently in the schema the field barcode does not exist. So I don't know what value comes into the barcodeValue but I assumed it to be undefined and console.logging it confirmed this..

however if I add the barcode field in the database and keep it empty, the barcodeValue is treated as falsy and it works fine.. so the value of an empty field is falsy but the value of non-existent field (even though it shows as undefined) is not falsy..

But if the barcode field does not exist in the database, I assumed it would be undefined and it would still work. But it doesn't.. I tried to google this but couldn't find an explanation..

If the above question doesn't anger you (as my previous query did) and you can treat it as a genuine query, I would appreciate some guidance..

Here's the button

  <button class="btn ticket__print-ticket" data-id=${user._id} data-barcode=${user.barcode}> Print Ticket </button>
  </div>

Here's the argument being sent on event

  if (modalContent) {
  modalContent.addEventListener("click", function(e) {
    e.preventDefault();

    if (e.target.closest(".ticket__print-ticket")) {
      const printTicketBtn = e.target;
      const id = printTicketBtn.dataset.id;
      const barcode = printTicketBtn.dataset.barcode;

      console.log(id, barcode);

      printTicket(barcode);
    }

And here's the code that does not respond when the database field does not exist (even though it shows as undefined when I console.log it

Image to show the value of barcode is undefined


export const printTicket = async function(barcode) {
  // console.log(barcode)
  if (!barcode) {
    console.log("in");
    showMessage(
      "Ticket Not Ready",
      "The ticket process requires approval and should be completed soon. You will have a response soon. However you can show the QR Code at the Entrance and generate the ticket immediately"
    );
    return;
  }
about 4 years ago · Juan Pablo Isaza
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!