In other words the important difference between JPEG and Raw is
bit depth. JPEG is a lossy, compressed, finished, ready to print file type that has little, if any, editing headroom.
JPEG is limited to an 8-bit color depth.
Raw is 12 or 14 bits, and virtually all digital photographs start out as a 12-bit or 14-bit Raw image data file in the camera.
JPEG conversion can be done in or out of the camera. Record the Raw file to the camera memory card if
you want to do the JPEG conversion yourself after editing the photo. Otherwise the JPEG conversion will be done according to software in the camera some group of camera engineers wrote, and the crude editing adjustments the camera menus provide.
The bit depth is about how many distinct colors a photo can have in each of the 3 color channels digital photography is baewd on - red, green, and blue (RGB)
The biggest 8-bit digital number possible is 11111111, and 11111111 = 255. So a photo that has an 8-bit color depth can only show a maximum of 256 colors per color channel.
12-bits is 111111111111, and 111111111111 = 4096 which can show 4096 colors per color channel.
14-bits is 11111111111111, and 11111111111111 = 16,383 which can show 16,383 colors per channel.
To get from the 12-bits or 14-bits Raw image data file the camera starts out with the vast majority of the original color data in the photo is discarded.
That's why JPEG is called a lossy (data is discarded), compressed file type (files are smaller files than the Raw file they are made from).
JPEG retains all of the luminosity data the camera recorded, because the luminosity is needed for humans to correctly perceive the photo.
Bit Depth
Tutorials The RAW File Format
Tutorials Color Perception
Overview of Color Management (3 parts)