Basically, a 401(k) can have what is called a "loan", but is more properly a "structured withdrawal and repayment agreement". This allows you to access your nest egg to pay for unforeseen expenses, without having to actually cash it out and pay the 10% penalty plus taxes.
You can get up to half of your current savings, with an absolute cap of $50k, minus the balance of any other loan outstanding. While there is a balance outstanding, you must make regular scheduled payments. The agreement does include an interest rate, but basically that interest money goes into your account. The downside of a 401(k) loan is the inflexibility; you must pay the scheduled amount, and you also have to keep the job for which you're paying into the 401(k); if you quit or are fired, the balance of the loan must usually be paid in 60 days, or else the financial institution will consider the unpaid balance a "withdrawal" and notify the IRS to that effect.
Now, with a Roth account, it works a little differently. Basically, contributions to any Roth account (IRA or 401(k)) are post-tax. But, that means the money's now yours; there is no penalty or additional taxes levied on any amount you cash out. So, a loan basically just provides structure; you withdraw, then pay back under structured terms. But, if you need a little cash for a good reason, it's usually better just to cash out some of the principal of a Roth account and then be disciplined enough to pay back into it.