As a rule of thumb, the hardware in a decent laptop will be "up to date" for two years, and the laptop can be expected to have a lifespan of 4 years during which it requires 1 or more repairs, after four years it may accumulate problems beyond the capability of economical repair. A desktop will be "up to date" for two years, likely run into a small problem within 4 years ($50 to $100 to fix), and can last 6 years before the cost of repair exceeds remaining value. Laptops are more expensive to repair, and are more likely to have problems that are impossible to repair.
lifespan depends entirely on how you use the machine.
The fastest way to destroy a laptop is to place it on a bed while it is running. This prevents hot air from escaping under the laptop and causes parts to overheat. This results in excess wear and tear of the silicon chips (which expand with heat and contract when cooled). A laptop that is usually left on a bed overnight is lucky to last a year without expensive or permanent hardware damage.
Similarly, desktops that are not allowed to ventilate properly will encounter problems within 3 years, probably sooner, depending on the hardware (more advanced and powerful hardware produces more heat, thus causing more damage).
Laptops are subject to more abuse than desktops, which is why laptops have shorter lifespans.
If the average laptop made today were placed in a clean, well ventilated room, it could likely run for 10 years without problem if no one touched it. A desktop would probably last 15 years without problem in the same condition.
Technically, computer components can run forever, if kept on and at full power without interference. For example, many of the satelites orbiting the Earth have been there for two or three decades and continue operating. They are subject to considerable abuse when launched from Earth, but are in a perfectly clean environment since then, and are properly shielded from solar radiation.