I would like to understand what is the real use of !! in JavaScript. I tried with few different validations to understand the purpose of !!. But all tries resulted in same output.
var a; // undefined
if (a) {
console.log('1');
} else {
console.log('2');
}
if (!!a) {
console.log('1');
} else {
console.log('2');
}
For all the following scenario, I get only 2 printed in console. a = null; a = '';
Could anyone please explain this in detail?