When I am in the world, I am the Light of the World.
This episode leads into John 9:39 where Jesus metaphorically explains that he came to this world, so that the blind may see.
In the Christological context, the use of the title Light of the World is similar to the Bread of Life title in John 6:35 where Jesus states: “I am the bread of life: he who comes to me shall not hunger.” These assertions build on the Christological theme of John 5:26 where Jesus claims to possess life just as the Father does and provide it to those who follow him. The term “Life of the World” is applied in the same sense by Jesus to himself in John 6:51.
You are the light of the world. A city on a hill cannot be hidden. Neither do people light a lamp and put it under a bowl. Instead they put it on its stand, and it gives light to everyone in the house. In the same way, let your light shine before men, that they may see your good deeds and praise your Father in heaven.
This application of "light compared with darkness" also appears in 1 John 1:5 which applies it to God and states: "God is light, and in him is no darkness at all."