A shadow is simply "a point the light can’t see." Shadow mapping implements that literally: first render the scene from the light’s point of view (not the camera’s), storing each point’s depth in a texture (the shadow map), then when rendering from the actual camera, paint a pixel as shadowed if it sits farther away than what the light "saw" at that spot.
Setup spans three places: renderer.shadowMap.enabled = true turns the feature on; mesh.castShadow = true goes on objects that should cast a shadow, mesh.receiveShadow = true on things like the floor that should show one. On the light itself, set light.castShadow = true along with light.shadow.camera (the range over which shadows get computed) sized to the scene — too wide and shadows go blocky from insufficient resolution, too narrow and objects fall outside the range and get clipped shadows.
Setting renderer.shadowMap.type to PCFSoftShadowMap softens shadow edges slightly. The demo bounces a ball up and down, and its shadow on the floor grows and fades depending on how high it is.
When to use
Whenever the scene needs to visually communicate whether an object is floating or resting on a surface — essentially every 3D scene.