Dan*_*llo 8

它将您的值转换为布尔类型:

var x = '1';
var y = !!x;

// (typeof y === 'boolean')
Run Code Online (Sandbox Code Playgroud)

另请注意以下事项:

var x = 0;
var y = '0';       // non empty string is truthy
var z = '';

console.log(!!x);  // false
console.log(!!y);  // true
console.log(!!z);  // false
Run Code Online (Sandbox Code Playgroud)