Why is there ear wax in your ear?

To clean out your ear and prevent bacteria/viruses from taking over this opening in your body. Earwax acts as a barrier and a first line defense system for your body's immune system.