In some code I have seen a double negation !!
in front of a variable, for example:
{ token: !!localStorage.getItem('token') }
I understand that a negation is used !
to perform a logical negation on an expression.
But a double negation converts it back to the state as it was originally received, for example:
var token = true;
console.log( token ); // true
console.log( !token ); // false
console.log( !!token ); // true
For what and why is this technique used in JavaScript?