David was experienced at facing fierce opposition and threats to his life. As was said earlier, David had acted bravely when he didn't feel like being brave, facing the lion and the bear. Now, when Goliath threatened, his courage was strong enough to meet the test. One of God's purposes for the trials of life is to strengthen our courage. God lets us endure threats and danger to demonstrate to us that He will be present with us in our struggles.
Commitment establishes courage.
David's courage was preceded by conviction, strengthened by conquests and established by commitment. His commitment was to God and God's promises of direction and protection. Many Bible scholars believe David wrote Psalm 23 when he faced Goliath. In verse 4 he claims God's promise of His abiding presence. John Wesley understood well the importance of the virtue of courage in the spread of the gospel.