Frequently when I am using a spreadsheet I find I accidentally started to type in another cell, erasing what was in that cell.
Do not press enter or tab, simply hit escape and it will undo the mistake.
If you did accidentally type over a cell and did not press escape before you noticed there is an undo button. Hold down the Control key (Command on a Mac) and hit Z to undo.
If you do not want to lose the new thing you typed. Click on the cell. Use Control C to copy and then use Control Z to undo your typing. What you typed into the cell is saved to your clipboard so put your cursor in a new cell and use Control V to paste.