Smoke alarms come in two categories (sometimes combined). Photoelectric and ionization.
The lifetime is directly related to the technologies and the environment.
The technology limitation of the ionization is that a small amount of a radioactive isotope is used to ionize the air/particle near the electrostatic detector plates. The particles attracted to the plate indicate particles (smoke) in the air.
The radioactive isotopes decay and the ionization grows weaker - thus impairing the ability of the alarm to count as many particles.
Environmental conditions can also impact lifetime. Smoke can build up on electrostatic plates (ionization type) and impair their ability. Similarly smoke can build up on photoelectric emitters and detectors.
The detectors do attempt to detect these issues and one (not guaranteed) response is to beep to annoy you into their replacement.
As it's difficult to vette these impairments over time it is truly best to replace them every 10 years or so and the batteries every year (put the partially used batteries in less critical items).
Here's a very approachable short summary I found to accompany this response:
Consider a smoke alarm in a kitchen. Boiling pasta water - particulate laden water vapor; stir fried foods, pan fried meats, burn off of spills on the range.
In particular the greasier smoke from cooking for example is particularly likely to impact both photoelectric components as well as ionization electrostatic plates.
So kitchen alarms are often the most critical to replace early and often.
Other places to watch are bathrooms (steamy water, particularly if not very soft), shops and garage (think sawdust), your porch near your smoker.
Please don't wait until they fail into constant beeping to replace them. That's their last ditch notice to you and they've likely been highly compromised long before then.