A comparator is an integrated chip that compares two voltages on its legs and provides a digital output based on the inputs.
In a comparator ( as shown above in the diagram) , the V+ input votlage and the V- input voltage are compared. When there is more voltage in V+ then in V- ,the output of the triangle( comparator) is logic 1, or + 5 V when the voltage in V- is greater , then the output is 0. For example , if V+ is 5 volts and V- is 3 volts, then the output of the comparator will be 5 volts.
Now to use this comparator with any variable resistance sensor ( like a photocell) you connect one pin of the sensor to V- and a resistor to V+. Once the sensor achieves a voltage lower than the resistor's voltage , the output of the comparator will be +5 volts and the LED wil turn on .
Thanks ed1380 for the schematic
Now comparators come in multiples , and in chips together. Like in the LM339 chip there are 4 comparators built in.
For more info visit the links below ( which are also my sources)