This will cause the second note to sound, even though the right hand only produces the first note. The vibrations, caused by the sound of the first note will be transferred to the sound of the second note. 
Why it is used
The hammer-on is used by guitarists to improve the smoothness and the flow in the songs they play. Without hammer-ons, a song will sound very simple and won't reach its full potential. 
Hammer-ons are mostly used in solos, as well as in fingerpicking and arpeggios. 
Hammer-ons are useful for making passages easier for your picking hand by producing the sound of a note with your fretting hand.
Hammer-ons are usually used together with pull-off technique as a part of legato.
History of the technique
In "Ellis's Thorough Course For 5 String Banjo" written around 1900, the term 'Hammer on' is used to define the action of performing technique called 'the Shake': "The Shake, which is marked 'tr', is played in the following manner. Strike (pick) the first note only with the right hand & the remainder of the passage with the 2nd finger of the left hand, by 'hammering on' the string while it is vibrating".
The term hammer-on was first created by Pete Seeger in his book "How to Play the 5-String Banjo" in 1962.
Though now it's impossible to name the first guitarist, who applied the hammer-on technique to guitar, it needs to be said that Eddie van Halen pushed the limits of hammer-on expertise and spiced it up with a tapping technique.
In tabs, hammer-ons are usually represented by the letter 'h' accompanied by numbers to the left and right. E.g.:
e|-----| B|-7h8-| G|-----| D|-----| A|-----| E|-----|
Songs for practicing Hammer-on
Led Zeppelin - Over The Hills And Far Away
"Over the Hills and Far Away" guitar lesson