Check your local laws on if it is legal. In some places yes, other places no.
If it is legal, then must you decide what to do. Depends on road conditions, sidewalk conditions, your tolerance for traffic, how fast you need to go.
My preference is for road. If the road is too busy for my taste (and I have a high tolerance for traffic) I look for an alternate road route. If no good alternate exists, I'm fine with riding the sidewalk as needed.
As mentioned, sidewalk riding is as dangerous as road riding, so be alert.