In Section 6 of "Song of Myself" Whitman uses the imagery of grass to explore the theme of death and rebirth. The child asks the speaker what seems like a fairly simple question: "What is grass?" But the speaker is unable to give a definitive answer. Instead, he can only offer possible suggestions, one of which is that the grass is itself a child, growing out of the realm of death into a new life.
Grass indicates the presence of life, even in the setting of a graveyard. The grass sprouts from among the graves, this "beautiful, uncut hair" showing us that there is really no death. And even if there were such a thing, it would merely lead towards new life. That's why for Whitman grass is a sign of hope corresponding to his naturally optimistic disposition.