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".
Light and darkness in John’s gospel is an antithesis that has symbolic meaning and is essential to understanding the author of John. The fourth ::gospel expresses certain ideas using the antithesis more frequently than any other writings in the New Testament. The Johannine community may ::have borrowed the symbolic use of the antithesis Light-Darkness from Essene literature, “which considered History as a permanent conflict between ::Good and Evil, using Light as a symbol of Truth and Righteousness and Darkness as that of Falsehood and Evil”
"In John's writings, walking in darkness does not mean committing acts of sin but rather, rejecting God's message of eternal life through Christ" Those who define darkness as sin also define light as good and righteous. However, in the Gospel of John light is never defined as righteous. Light is defined as life, as seen in John 1:4, “In Him was life; and the life was the light of men”. Those have faith through Him will have eternal life. This “life” is a gift Jesus brought from God into a dying world. In John, “darkness is present in the absence of light; the absence of eternal life,” and darkness referring to death, spiritually. Those who walk in darkness do not have eternal life because they are unknown to God. The only way to receive "life" is to be known of the light through God and his promises.