Gastroscopy is a crucial tool in the diagnosis of gastrointestinal cancers, such as stomach cancer and esophageal cancer. It allows for direct visualization of abnormal tissues, and biopsies can be taken during the procedure for histopathological examination to confirm the presence of cancer cells.