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 :: es6 class 
Javascript :: noty js 
Javascript :: react portals 
Javascript :: oops in js 
Javascript :: when to use previous state in useState 
Javascript :: adding more than one class react 
Javascript :: get vue-emoji-picker 
Javascript :: javascript loop aray 
Javascript :: Format javascript date with date.js library 
Javascript :: notification react native 
Javascript :: button clicker code 
Javascript :: angular file upload 
Javascript :: how to select a dom element in react 
Javascript :: vue js skeleton loading 
Javascript :: break out of map javascript 
Javascript :: google analytics nextjs 
Javascript :: prisma database example 
Javascript :: javascript get 
Javascript :: javascript date objects 
Javascript :: comming soon page in react 
Javascript :: react navigation 4 
Javascript :: insert a data into mongo using express 
Javascript :: delete icon 
Javascript :: interval in javascript 
Javascript :: end of file expected json 
Javascript :: arrays 
Javascript :: node.js Readable Streams 
Javascript :: js arrow vs normal function 
Javascript :: javascript syntax of throw statement 
Javascript :: javascript symbol 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =