The 10K resistor keeps the pin in a LOW state until the button is pressed. The comparatively high value of the resistor ensures that only a small amount of current flows
Keeping the pin in a known state at all times prevents the input floating at an unknown, maybe HIGH, maybe LOW state when the button is not pressed. The resistor is technically known as a pulldown resistor
Welcome to the forum
Be aware that, although this gives a good example of preventing a floating pin, it is not the typical way a button is wired in arduino. Because the microcontroller has internal resistors connected to VCC (5V) that can be activated in the code (PinMode input pullup) it makes sense to use these rather than to add an external resistor. It achieves exactly the same thing but pulls the pin high rather than low so the logic is reversed compared to your example. You wire the button to GND and When you push the button the pin is pulled low and thus LOW == pressed.
The concept to be aware of is that the pin can not be left “floating” ie not connected to a reference voltage (gnd or vcc via appropriate resistor) as the voltage detected at the pin will then be indeterminate ie it can float around from high to low picking up interference etc and can not be trusted to be any particular voltage and thus can’t be used in button logic.