The epidermis is the outermost epithelial layer over the skin. This is what you see and touch. It is made up mostly of keratinocytes.
Clearly this layer protects the layers beneath, i.e., the dermis and the subcutaneous layer which both have more delicate functions. It keeps out dirt, debris, bacteria, and basically everything else you don't want inside you. It also forms a protective barrier that protects from damage.
Within the epidermis, melanocytes create melanin to help protect from UV-rays. Lymphocytes and Langerhans cells help to neutralize pathogens.