I have been continuously employed or have had substantial contracting since 1999 (almost all regular employment, except for no more than a total of 12 months of various freelance).
I can only guess why, but it is probably some combination of:
1. When the layoffs came, I was in the non-laid-off remnant, probably because I always situated myself to know how everything worked, soup-to-nuts: code, databases, servers, etc.
2. Constant re-education, and willingness to use languages and tools I considered to have technical deficits (e.g., ColdFusion).
3. Constant teaching. Was always teaching Java or, later, Ruby in the evenings. Stayed sharp.
4. Constant networking. Very important -> I networked both at the tech level and at the business level. Keeping in touch with VPs of marketing and business development meant that when their cohort was looking for devs, the business-side VPs would think of me. Techie-to-techie referrals were nil.
5. Maturity. Was recruited into an executive position in 2002 perhaps because of attitude + tech skills.