At home
First, get yourself under a sturdy table, desk, etc. to protect your head from falling objects. If this is not possible, then protect your head with a cushion or pillow.
Turn off all stoves, heaters and similar appliances as soon as you can. Make a habit of switching off the gas, even in a minor earthquake. .
The door may be damaged and malformed by a strong earthquake and cannot be opened, trapping you in the room. To avoid this, open the door quickly to secure a way out.
Do not rush outside. Buildings are made to resist earthquakes of strong magnitude.
In contrast, if you go outside, the risk of being hurt by falling objects from the rooves or floors above is very high. Also, you should never use elevators.