DEV Community

eddiejpot
eddiejpot

Posted on

Java Script Truthy/Falsy & Logical Operators

Falsy Values

  1. null
  2. undefined
  3. NaN
  4. 0
  5. "" empty quotes
  6. false

&& and ||

&&

  • Returns the first falsy value
  • If none found, it will return the last truthy value

||

  • Returns the first truthy value
  • If none found, it will return the last falsy value
// both are truthy
truthy1 && truthy2; // truthy2
truthy1 || truthy2; // truthy1

// both are falsy
falsy1 && falsy2; // falsy1
falsy1 || falsy2; // falsy2

// 1st truthy, 2nd falsy
truthy1 && falsy1; // falsy1
truthy1 || falsy1; // truthy1

// 1st falsy, 2nd truthy
falsy1 && truthy1; // falsy1
falsy1 || truthy1; // truthy1
Enter fullscreen mode Exit fullscreen mode

Top comments (0)