For a laptop the typical lifespan of the laptop computer is around 3 years. By that time even if the laptop is still powering on the battery is usually not keeping charge anymore and it's not really portable anymore since you always have to have it plugged in.
For a desktop they can last decades if properly cared for. To increase the lifespan of your desktop computer make sure you keep viruses out, keep the inside of the case clean etc.
Take care of your desktop computer and it should last you at least 10 years. By that time you'll likely want to replace it with a newer one anyway because things such as software and other things will be outdated and will not run on the older spec desktop.