Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js double exclamation mark

// "!!" converts a value to a boolean, then inverts it and then inverts it again.
// So let's say you want to check the value for a given variable:
const num = null; 

if (num) { // false -> value is null -> evaluated as falsy
}
if (!num) { // true
}
if (!!num) { // false
}
// another example
const str = "Hello World";

if (str) { // true -> value is a "proper" (not empty) string -> evaluated as truthy
}
if (!str) { // false
}
if (!!str) { // true
}
Comment

double exclamation mark js

// Converts anything to boolean. 

!!false === false
!!true === true

!!0 === false
!!1 === true

!!parseInt("foo") === false // NaN is falsy
!!-1 === true               // -1 is truthy
!!(1/0) === true            // Infinity is truthy

!!"" === false              // empty string is falsy
!!"foo" === true            // non-empty string is truthy
!!"false" === true          // ...even if it contains a falsy value

!!window.foo === false      // undefined is falsy
!!null === false            // null is falsy

!!{} === true               // an (empty) object is truthy
!![] === true               // an (empty) array is truthy; PHP programmers beware!
Comment

double exclamation mark javascript

Double Exclamation
Comment

javascript double exclamation mark

console.log(!!navigator.userAgent.match(/MSIE 8.0/));  
// returns either true or false
Comment

javascript double exclamation mark

const isIE8 = !! navigator.userAgent.match(/MSIE 8.0/);  
console.log(isIE8); // returns true or false 
Comment

PREVIOUS NEXT
Code Example
Javascript :: sort array without using sort function in javascript 
Javascript :: add image to center in canvas 
Javascript :: array reverse 
Javascript :: javascript program to find largest of 2 numbers 
Javascript :: menu with dynamic submenu in javascript 
Javascript :: how ton give form widget to zoho creaor 
Javascript :: javascript to typescript converter 
Javascript :: javascript$.4908BEAMpacidE 
Javascript :: auto linting and testing in react tyescript 
Javascript :: random jwt secret key generator 
Javascript :: using Canvas with tkinger draw arc 
Javascript :: javascript declaring variables 
Javascript :: react native time set state 
Javascript :: how to convert numbers to roman numerals in javascript 
Javascript :: Plumsail - DataTable Cascading Dropdowns 
Javascript :: if the params of usequery updated 
Javascript :: Number o flines of typography element react material 
Javascript :: Fetch data changing on reload from array to undefined 
Javascript :: dependent drop down list in jquery 
Javascript :: angularjs how to get a response from a post request 
Javascript :: How to call keyup function on textbox for every dynamic generated form in Angular8 
Javascript :: convert base64 formatted data to image using AngularJs 
Javascript :: Context: Cannot read properties of undefined 
Javascript :: python regex consecutive characters 
Javascript :: express and jade, ignore render errors 
Javascript :: javascript check if key is keydown is charcter 
Javascript :: Printer Errors 
Javascript :: bullet mechanism in phaser 
Javascript :: string to date with ist javascript 
Javascript :: JavaScript: Cycle through three-state checkbox states 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =