a “U” shape before going into the wall. That is called a P-trap. Its entire job is to hold a small pool of water.
That little pool of water acts as a physical, liquid seal. It is what blocks heavy, smelly sewer gases from floating up the pipe and into your bathroom or kitchen. It also blocks drain flies and bugs.