There are two types of files: raster and vector. The most common, the first ones, use thousands of pixels to build an image and their most common formats are JPG, GIF and PNG. When generating a file of this type, it must be taken into account that its size cannot be changed without losing quality, since the size of the pixels would change, becoming deformed and causing the image to lose quality.
Vector files are much more flexible as they rely on mathematical equations, so they will continue to have pristine image quality even if they are resized. That is why graphic designers often use this type of format to be able to adapt all their designs to any medium. Also, vectors can be converted to JPG and PNG very easily.
JPG: The most common photo file. On many occasions they are optimized to reduce the weight of the image, but this entails a loss of quality and it could become grainy.
PNG: They are like a JPG file, but they do not offer the possibility of being optimized. On top of that, their greatest feature is that they can have transparent backgrounds, so they are very useful if you want to put the image on some kind of background.
GIF: This format is used to make small animations, being an excellent option to generate icons and simple elements with movement, but not for images.
EPS: This is often used for elements such as icons, as they are a highly compatible format with recent and past versions of Illustrator.
Ai: The most common format to save the files generated in Adobe Illustrator. They are commonly used by graphic designers, logo designers, illustrators, etc.
SVG: These are vector file formats for the web. For example, if you want to create an animation and hang it on a web page, this format is ideal so that the quality remains high and the design does not become pixelated or grainy.