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

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