Greetings,
First, check your local laws to learn if it is legal. It is not legal in many places.
Second, if riding a bike is legal on a sidewalk, pedestrians always have the right of way.
Third, be courteous and leave the sidewalk or hop off your bike and walk it whenever you approach pedestrians unless there is a dedicated bike lane (which is rare for sidewalks).
Where I live in Michigan, it is legal to ride on sidewalks but the only time I do it is to avoid a particularly nasty stretch of rough brick road. If pedestrians are on the sidewalk, I either leave or walk.
Kind regards, RoadLight