Nothing kills your confidence more as a software developer than being laid off. You start asking yourself uh why me? Why not others? Maybe I'm not as good as I thought. What can I do better? Maybe I need to learn a new framework or go back to uni and what the hell am I going to tell the next company looking to hire me? Before you freak out, you need to understand the dynamics that happen in software development.
Software dev is mostly project work. When business is good, there are plenty of projects. When business is not so good, not so many projects. Layoffs happen all the time and because developers are expensive and projects come and go. Now, even when you know this, getting told to pack your things and go will still hurt. It's just the way it is. So what you want is to develop an attitude that is I will do my best and whatever happens happens.
Don't be so attached to the outcome. This kind of resilience takes time to develop, but it definitely pays off. Most times, things will turn just out fine and you have an amazing career.