Specifically, as a fighter with a javelin, would I be able to throw it at a target in melee range, rather than using it as a melee weapon? I’m curious if I could get the extra damage from a Javelin of Lightning on a reaction attack from the Mage Slayer feat.
You can attack with disadvantage
There is no lower limit on the range of an attack with ranged weapons, except for rare exceptions like the mangonel, where the weapon text explicitly says so. However, using a ranged weapon on an opponent within 5 feet of you will impose disadvantage. The rules in the Combat section of the PHB say:
Ranged Attacks in Close Combat Aiming a ranged Attack is more difficult when a foe is next to you. When you make a ranged Attack with a weapon, a spell, or some other means, you have disadvantage on the Attack roll if you are within 5 feet of a Hostile creature who can see you and who isn’t Incapacitated.
As pointed out by Exempt-Medic, using the javelin as a ranged weapon will not work for the purpose of making a reaction attack with the Mage Slayer feat. Mage Slayer states (emphasis mine):
you can use your reaction to make a melee weapon attack against that creature
so you cannot use it to make a ranged attack. The javelin is a melee weapon that can be used as a ranged weapon, so you could just use it as a melee weapon on an opponent next to you, without disadvantage.
Javelin of Lightning
Used for a melee attack, though, you would have to forgo the lightning effect, as the Javelin of Lightning states
When you hurl it and speak its command word, it transforms into a bolt of lightning
The lighting effect is available only when using it in a ranged attack.
The net result of all this: you will not be able to hit somebody with lightning from a javelin of lightning when using your mage slayer feat.
Yes, you can
However, the attack roll will be made with disadvantage.
It does seem like a waste of a Javelin of Lighting use to just attack one person, though.