The earnest money deposit is a "show of good faith" that underscores the buyer's seriousness of purpose and gives confidence to the seller to be able to take the property off the market during the "due diligence" or escrow period (from contract to closing, usually 30-45 days).
The buyer's earnest money check is not deposited in an escrow account until there is a signed and accepted (i.e. "ratified") contract, and will be governed by state law handling of escrow accounts.
When we represent buyer clients, we usually include 6 contingencies that our clients can use to release a contract "with cause" and get their earnest money deposit refunded in full:
The buyers would lose their earnest money deposit if they don't perform on the contract "without cause" (for example if they just change their mind after all the contingencies have been satisfied).
If the transaction is completed successfully (i.e. "closed") your earnest money deposit is credited to you and becomes part of the buyers' downpayment (if no downpayment was required and the seller is paying for all the closing costs and prepaid expense, then the buyers' earnest money may be returned to them at closing).