What is the history behind "foreign legions"?

by Colosso95

What I'm specifically curious about is the establishment of modern combat units made entirely of foreign personnel.

What was their intended purpose? Were they just a way to lump up any foreigner who came to fight for a country or did they actively recruit in foreign countries? Did they operate in any particularly different ways?

The French Foreign Legion is obviously the most famous one but is there a difference between it and the ones that exist or have existed in other countries' armies?

Georgy_K_Zhukov

For the French Foreign Legion, this and this should both be of interest.