"!!" in JS

var o={flag:true}; var test=!!o.flag;//equivalent to var test=o.flag||false; alert(test);

Since the ! operator for null and undefined will produce a true result, the effect of using two exclamation marks is that if the value of flag in o is explicitly set (non-null/undefined/0""/equivalent), naturally test will take the same value as o.flag; if not set, test will default to false, not null or undefined.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325469906&siteId=291194637
js