Editing requires a totally different mindset than writing. One is a creative process and one is a critical process. Few people can do both well at the same time.
Editing is usually easier if you separate it from the creative process of writing. Most writers find that worrying about things like spelling, grammar, word choice, and sentence structure while writing a first draft impedes creativity. Don't worry about being perfect the first time. Just get the words on paper and go back and edit later.
It helps to allow a little time for the writing to "cool". If you reread your writing as soon as you're finished, you're still in the same mood you were when you put the words on paper. If you felt like the words were flowing, you're still in the glow of creativity. If you reread immediately, you're going to see your words with rose-colored glasses. You'll be resistant to making changes that might be needed.
If you hated writing, if you felt like adding each new word was like pulling a tooth, then you're going to be overly critical if you reread immediately. You'll think every sentence is garbage and be tempted to trash the whole thing and give up. At best, you'll waste time making changes that don't need to be made.
Another problem is that your mind remembers what you meant to say. When you reread right away, it fills in a word you may have left out or misspelled. You can see what you meant to write and not even notice your mistakes.
Give yourself a couple of hours or whatever time you need to detach yourself from the creative process. Go back and try to read as if you've never seen the words before, as if you have no emotional investment. That can be hard to do, but it's a necessary part of writing. No one gets it totally right the first time.
Every writer has different strengths and weaknesses. They usually have a specific list of things they look for when they are editing. If you have a word processing program, Spell Check and Grammar Check can be a big help. But you can't rely on them totally.
You also want to think about things beyond the mechanics of grammar and punctuation. Ask yourself questions. Does this make sense? Is what I mean clear? Is the tone right? Can I say that in a better way so the reader gets a better picture? Am I being too wordy or too sparse? Does this sentence or paragraph belong here? Would it be better in another place or left out completely? Would I want to keep reading if I read the opening paragraph for the first time? Do I feel satisfied with the ending?
If you're writing fiction, there are other questions. Does this character seem real? Are his actions believable? Do I care what happens to this character?
A word of caution; don't get so caught up in trying to make your work perfect that you never finish it. There are people who spend years trying to polish their writing to perfection. Sadly, no one ever sees their writing, because they always think they can make it just a little bit better.
If you spend too much time on one piece of writing, you lose the initial spark that made you want to write it. The words may be perfect, but the soul of the writing is gone.
Write as well as you can, correct your mistakes, and move on. The more you write, the better you get.