mercredi 8 septembre 2021

"!" in the IF Statement - what does it mean? [duplicate]

I have 3 questions about my code here...

  1. I am trying to understand what the ! before the passenders.paid means?
  2. And also, what other options do I have for putting operators before the logic?
  3. In this example, why are all my answers true when Sue has false?
var passengers = [{
    name: "Jane Doloop",
    paid: true
  },
  {
    name: "Dr. Evel",
    paid: true
  },
  {
    name: "Sue Property",
    paid: false
  },
  {
    name: "John Funcall",
    paid: true
  },
];

for (var i = 0; i < passengers.length; i++) {
  if (!passengers.paid) {
    console.log(true);
  } else {
    console.log(false);
  }
}

Aucun commentaire:

Enregistrer un commentaire