1document.getElementById("myBtn").addEventListener("dblclick", function() {
2 alert("Hello World!");
3});
1// Converts anything to boolean.
2
3!!false === false
4!!true === true
5
6!!0 === false
7!!1 === true
8
9!!parseInt("foo") === false // NaN is falsy
10!!-1 === true // -1 is truthy
11!!(1/0) === true // Infinity is truthy
12
13!!"" === false // empty string is falsy
14!!"foo" === true // non-empty string is truthy
15!!"false" === true // ...even if it contains a falsy value
16
17!!window.foo === false // undefined is falsy
18!!null === false // null is falsy
19
20!!{} === true // an (empty) object is truthy
21!![] === true // an (empty) array is truthy; PHP programmers beware!
22
1let a = null;
2const b = a ?? -1; // Same as b = ( a != null ? a : -1 );
3console.log(b); // output: -1
4//OR IF
5let a = 9;
6const b = a ?? -1;
7console.log(b); // output: 9
8
9//PS.,VERY CLOSE TO '||' OPERATION IN FUNCTION, BY NOT THE SAME
1!oObject // inverted boolean
2!!oObject // non inverted boolean so true boolean representation
1// convert to boolean
2// The following examples are the only values which result in a false expression
3
4!!0 // false
5!!"" // false
6!!null // false
7!!undefined // false
8!!NaN // false
1const isIE8 = !! navigator.userAgent.match(/MSIE 8.0/);
2console.log(isIE8); // returns true or false
3