I think the bulletproof way is:
if (typeof $.cookie('token') === 'undefined'){
//no cookie
} else {
//have cookie
}
Checking the type of a null, empty or undefined var always returns 'undefined'
Edit:
You can get there even easier:
if (!!$.cookie('token')) {
// have cookie
} else {
// no cookie
}
!!
will turn the falsy values to false. Bear in mind that this will turn 0
to false!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…