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 :: destructuring nested objects 
Javascript :: jconfirm button 
Javascript :: css striped background 
Javascript :: fastify query 
Javascript :: insertar al inicio de un array javascript 
Javascript :: render and mount functional component 
Javascript :: javascript dom methods list 
Javascript :: javascript onsubmit change input value 
Javascript :: js xor 
Javascript :: dual array javascript 
Javascript :: Get home directory in nodejs windows 
Javascript :: vue resources post 
Javascript :: javascript Passing Function Value as Default Value 
Javascript :: noscript you need to enable javascript to run this app. /noscript 
Javascript :: how to defined an array in js 
Javascript :: javascript loop array 
Javascript :: what is the use of consrtructors in reactjs 
Javascript :: money formatting javascript 
Python :: python suppress warnings 
Python :: uuid regex 
Python :: python - show all columns / rows of a Pandas Dataframe 
Python :: is pythin a real coding language 
Python :: string to date python 
Python :: python measure time 
Python :: mypy ignore type 
Python :: round python with list 
Python :: python random text generator 
Python :: running selenium on google colab 
Python :: generate a list of numbers upto n 
Python :: python get output of command to variable 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =