My advice: Have one or more side projects going all the time. If you get laid off, immediately start doing a startup, open-source project, or volunteering full time. A year of unemployment? Lonely, depressing, and not good on a resume. A year of launching an unsuccessful venture? Running coding classes for the underserved? Focusing full-time on contributing to pytorch? That's a lot better, both at the time and in ret…
This is a live-to-work attitude. Have some other hobbies and goals, and a year of unemployment will be neither lonely nor depressing. Personally I've gone farther in the work-to-live direction, with an easygoing, "boring" (still fulfilling enough to see some javascript doodad come to life, but not world changing) WFH job I perform well in that supports my homesteading and other hobbies.
You start to see the patterns and futility and cycles and think 'maybe my career is not making things better, it's keeping the mortgage paid?'
That and while I'm I can get rehired past 50...do I really want to do that dance again?