Earth's atmosphere and gravity are much heavier and stronger than either the moon, Mars, or even Mercury. If you have the regulatory controls to re-enter and land on earth safely, it's trivial to do it on any of those destinations.
It's still an incredibly hard challenge, and not might not work. But if SpaceX successfully reaches orbit and lands on earth with the Starship, landing on the moon and coming back is going to be an absolute cakewalk.
See the constantly stretching timeline for developing the Crew version of the Dragon capsule, despite the fact that SpaceX already had a working and tested rocket and pressurize capsule before they started on the crew version.
I'm optimistic that SpaceX can make some rapid progress here, but I wouldn't bet on the timelines holding for any of these human spaceflight projects.
There are nice tables at Project RHO illustration how much delta-v you can save by aerobreaking when traveling between Solar System bodies:
http://www.projectrho.com/public_html/rocket/appmissiontable...
You loose all of that for an airless body like the Moon. In this case it's not that big of an issue as moon is close & has a low gravity. If Mars was airless, it could be much more of an issue, as you are coming much more quickly from an interplanetary trajectory & there would be more gravity to handle during landing than on the Moon.
In terms of technical design creating a lightweight craft that can aerobrake to land on Mars is harder than the heavyweight craft that could do an airless powered landing. But once you factor in the booster requirements suddenly the atmosphere is making your job easier overall.
Can anyone comment on how Falcon 9 knows where it is? Is GPS part of the game? Because they dont have that on the moon or Mars.
On the Moon there's no atmosphere or erosion, so pattern recognition vs a known Lunar surface should work. Same should work to some extent on Mars.
As for spacecraft navigation in general you are using star/sun/earth trackers (depending of where your spacecraft operates) to detect your orientation. This is important to correctly point solar panels to the sun, radiators, cameras and sensitive instruments away from the sun and directional cameras to Earth.
As for detailed absolute position in space, AFAIK this is usually done by ultra sensitive radio signal ranging back on Earth.
But other means could be used, eq. taking picture of your target or other bodies you can resolve and then tracking their magnitude/size and position, possibly over time, to calculate where exactly you are in the Solar System so that you are seeing what you are seeing.
Creating a gps (like) network on mars with a bunch of satellites might actually be an option before landing. SpaceX appears to be already developing that capability in the starlink satellites for the DOD [0].
[0] https://www.c4isrnet.com/battlefield-tech/space/2020/04/06/t...
It's not like these are dumb birds, they can sit there for awhile collecting data to figure out their orbit, and then communicate that to the lander before it attempts to land.