As JPG is a lossy compression, every re-encoding losses quality. Thus, 90/180/270 degree rotation is a lossy operation as well. Is it possible to change orientation of JPG photo by changing some of its metadata tags so that the orientation can be changed without re-encoding the photo?
JPG can be rotated using only EXIF data, so no re-encoding is necessary.
I found this tutorial on the orientation flag - JPEG Rotation and EXIF Orientation
These days, most image apps can handle this flag, many can also write it.
Exiftool is a very comprehensive multi-platform solution that can handle all exif data - see How can I modify the EXIF orientation tag of an image?