What is the function of foreskin?

Hello, I was just wondering what the function of foreskin is for a male infant, and why it is important to have it amputated right after birth.

Update: Thank you so much for your help! I will not be choosing circumcision for my son after hearing this and seeing a video about it. It scared me, deeply. 😮‍💨 I'm a little shaken that I probably would have chosen it had I not looked into it a little more. No one tells me these things at the doctor's office.