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 :: how to add youtube videos to react app 
Javascript :: how to get the computer date and time jquery 
Javascript :: disabled radio button 
Javascript :: get value for radio button in jquery label 
Javascript :: check if isset variable js 
Javascript :: iife js arrow function 
Javascript :: jquery document ready function 
Javascript :: contains() js 
Javascript :: convert date and time into epoch javascript 
Javascript :: js check if two arrays contain same values 
Javascript :: find even numbers in an array javascript 
Javascript :: how to get value of html element in javascript 
Javascript :: javascript sort array of object by property 
Javascript :: antd dropdown stop propogation 
Javascript :: light font color to dark background using javascript 
Javascript :: alphabet to number javascript 
Javascript :: javascript set class on div 
Javascript :: js key value array 
Javascript :: how to run javascript in chrome 
Javascript :: javascript null or empty 
Javascript :: add property to all documents mongo 
Javascript :: Create MD5 hash with Node.js 
Javascript :: convert a new date standard to a yyy-mm-dd format in javascript 
Javascript :: jquery parent 
Javascript :: javascript textarea.append 
Javascript :: set 404 handling via express in node 
Javascript :: js stairs algorithm 
Javascript :: element clicked js 
Javascript :: javascript get call stack 
Javascript :: Return the average of the given array rounded down to its nearest integer. 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =