What is the function of surfactant in the lung?

Prevent collapse. Surfactant keeps the alveoli open during the expiratory phase of breathing. It reduces the amount of work needed for breathing.