How to avoid buying fake SD cards or tell if they are fake?

It may not be fake, but it could be used or broken.  Did it come in SanDisk packaging?

And why format a new device?  If it is new it doesn’t need to be formated.