= 0.4){zien()} then it gets red underlined with error "unreachable code". Why is that?? function loadLabeledImages() " /> = 0.4){zien()} then it gets red underlined with error "unreachable code". Why is that?? function loadLabeledImages() " /> = 0.4){zien()} then it gets red underlined with error "unreachable code". Why is that?? function loadLabeledImages() "/>

Why i get error "unreachable code" when i try to put an if in my function?

442 views Asked by At

When i insert "if (descriptions >= 0.4){zien()} then it gets red underlined with error "unreachable code". Why is that??

function loadLabeledImages() {
  const labels = ['Simon', 'Thomas'];
  return Promise.all(
    labels.map(async (label) => {
      const img = await faceapi.fetchImage(`./images/${label}.jpg`);
      const detections = await faceapi
      .detectSingleFace(img)
      .withFaceLandmarks()
      .withFaceDescriptor();
      const descriptions = [detections.descriptor];
      return new faceapi.LabeledFaceDescriptors(label, descriptions);

      if (descriptions >= 0.4){
        zien()
      }
    }),

  );

}

1

There are 1 answers

0
Quentin On

The fact is it an if is irrelevant. It is code that appears after a return statement.

When running the function, the JS engine will always return from the function before reaching the if. Since it can never reach the if, the if is unreachable.