Generally speaking, money invested in your retirement accounts should not be touched until retirement. The one exception is if you have an emergency and have a financial need related to health or even a death.
In fact, most employer-sponsored 401(k) plans allow for these type of "hardship loans." In most cases, even the hardship loans incur a 10 percent penalty and are taxed at ordinary income.
If you absolutely have to take out a loan from your 401(k), you need to prioritize this loan and pay it off first. Also, if possible, do your very best to try and continue to make contributions toward your plan, especially if your employer offers a company match. Passing up this match is the same as saying "no" to free money for your retirement.
4. What should you do if you're in a pinch and need money?
During times of hardship, your first step should be to assess your spending and find ways to cut back. What expenses in your day-to-day activities can you live without? If you are really in a bind and must get a loan, consider a home equity line of credit. Using your house to pay for major expenses and to cover you in a financial shortfall is a much better vehicle than tapping into money that will undoubtedly be your lifeline in your retirement years.