Because the characteristic of LED is forward conduction, forward voltage must be applied to both ends of it to light up. Usually the power supply is 5V. If no resistor is added, the current will be very large after being directly connected to the power supply, and it is easy to burn the LED. Adding a resistor can limit the current and protect the LED from being burned.