how they work? they are semicondutor junctions, etc etc. the experts are needed here. different materials internal produce different light colour external.
they are usually rated by their light output; how much of it they produce. also rated by forward voltage, light output colour, wavelength, lens dispersion, etc. get some data sheets, look through them.
you know what resistor to use by subtracting the led forward voltage, which might be 1V6, from your supply voltage, which might be 9V. then you pick a forward current, lesss than the max specified in the data sheet, less than will blind all the neighbours, and a bit less than will drain your battery (we'll assume) in an hour, so lets say 1mA. then you do ohm's law, R=V/I = (9 - 1V6)/0.001 = ? ohms.
this value resistor then limits the current by dropping a voltage, and the led doesn't self distruct. and that's how you test them. buy some leds, and some resistors, and a breadboard, and away you go.