I'm going to answer this one differently.
The purpose of the resistor is to limit the
current supplied to the LED. It does also drop some voltage, but that's not the most useful way to think about it, and I'll explain why.
Ohm's Law says that the relationship between current and voltage in a resistor is linear, and that the ratio of the voltage/current is the resistance. LED's do not obey Ohm's law.
In fact, the relationship between current and voltage in a diode is exponential--a small change in voltage can produce a huge change in the current that flows. This is why LEDs connected to voltage sources need a
current-limiting resistor, and that's why Japala used a resistor. To limit the current to the LED to a safe value (20mA is almost always a safe value).
Let's look at a couple of the suggestions previously given and analyze them:
Kc2iLq>It is possible that your LED can handle 5V (some do).
Tha's correct, but it's an incomplete answer, which is why I'm being so particular about the current. Modern blue LEDs are often rated for 5V, but they will carry a current at that voltage which is well in excess of the 20mA target current, maybe 5-10 times that. While the LED doesn't immediately fail catastrophically, it's forced to dissipate heat (equal to current*voltage) which shortens the life of the diode. Some LEDs are internally current-limited, but it's more common to find those set up to use 12V than 5V.
John Prophet>Another method may be to put two leds in a row (instead of the resistor) so that they divide the voltage between each other.
This is also partly correct. The problem again is that it doesn't limit the current effectively for every possible combination of LEDs, and it forces some assumptions and requires you to account for the cumulative forward voltage.
To illustrate, consider 2 blue LEDS in series with a 5V source. The rated forward voltage of each LED at 20 mA is somewhere around 3.6V, so this arrangement has a cumulative forward voltage of 7.2V, and the source will not drive the LEDs to the target 20 mA current. They may not light up at all, but they certainly won't be at full brightness. Two red LEDs would probably be slightly overdriven in this circuit, since you're driving them above the rated current.
The advantages of resistors are that they're cheap, and you can easily
calculate the size you need to limit current to a safe value if you know your LED's specs.