In my opinion borrowing from your 401K should be the second last thing you do with your $401k. The last thing would be taking a hardship withdrawal.
As Kbro stated, the money you borrow from "yourself" is no longer earning and this can cost tens of thousands in the long term. Also, and I think this is the real kicker, when you pay it back you pay it back from after-tax dollars and then when you withraw it at retirement you pay taxes AGAIN.
So $100 borrowed means you have to earn $120 to pay it back more or less.
Also, as far as I know, as soon as you quit your current job, your 401K loan becomes "due"