Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript truthy values and falsy values

// Truthy values

/*
	true
    {}
    []
    42
    "0"
    "false"
    new Date()
    -42
    12n
    3.14
    -3.14
    Infinity
    -Infinity
*/


// Falsy values

/*
  false
  0
  -0
  0n
  "", '', ``
  null
  undefined
  NaN
*/
Comment

Truthy and Falsy js

//Checking truthy and falsy value

function truthyOrFalsy (val) { 
    if(val) {
      return true
    } else {
      return false
    }
}

console.log(truthyOrFalsy(0)) // print false
console.log(truthyOrFalsy(5)) // print true
Comment

PREVIOUS NEXT
Code Example
Javascript :: speed facebook video with js 
Javascript :: hasOwnProperty with more than one property 
Javascript :: angular 10 set error on form controle 
Javascript :: bootstrap js link not working 
Javascript :: how to change the font family using jquery 
Javascript :: nvm check version 
Javascript :: importing react 
Javascript :: js iterate array index 
Javascript :: set timer jquery 
Javascript :: quicksettins.js 
Javascript :: if button is keeping pressed execute increment javascript 
Javascript :: js get element by class 
Javascript :: jquery create a button 
Javascript :: increase font size in jsx 
Javascript :: remove null values from json object in javascript 
Javascript :: process memory usage javascript 
Javascript :: check if it is a function javascript 
Javascript :: javascript find unique values in array 
Javascript :: mongodb unshift array 
Javascript :: javascript new date zero time 
Javascript :: javascript get random item from array 
Javascript :: javascript sort by id 
Javascript :: jquery trigger 
Javascript :: chack var exist for skip error on javascript 
Javascript :: check if date is valid 
Javascript :: react onclick new tab 
Javascript :: check if element is last child jquery 
Javascript :: outsystems close feedback message 
Javascript :: js watch window resize 
Javascript :: js detect hash change 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =