The gospel of John starts with a descriptive illustration of God's word going out from creation.
John 1:1: In the beginning was the Word, and the Word was with God, and the Word was God. 2. The same was in the beginning with God. 3. All things were made through him. Without him was not anything made that has been made. 4. In him was life, and the life was the light of men. 5. The light shines in the darkness, and the darkness hasn't overcome*n it. WEB
The language of this passage is challenging, and takes same thought to understand the meaning. For normal objects, the statements "A was with B" and also that "A was B" would seem to be inconsistent, so we are not looking for a precisely literal meaning, but rather one that is using language in an illustrative way.
In order to broaden the understanding, we can look at other sections of the Bible with similar concepts and language. A very obvious connection is to the very opening words of the Bible in Genesis 1:1,
Genesis 1:1: In the beginning God created the heavens and the earth. 2. Now the earth was formless and empty. Darkness was on the surface of the deep. God's Spirit was hovering over the surface of the waters. 3. God said, "Let there be light," and there was light. WEB
John 1:1 appears to have a reference to Gen 1:1 in using the phrase"in the beginning", so it is worth thinking of it against that context. In Gen 1, the process of creation was expressed in the form of "God said, ..." This ties in well with the idea of "the word". In Genesis we see that the process of creation was signalled words, and in particular, the words of God. That means that the word of God was there right from the beginning.