0

Angular 6 is here already, so in short tutorial provided by Medium i founded this lines of code.

else if (!!this.day4Name && !this.day5Name && days[date] !== this.day4Name) {
        this.day5Name = days[date];
        this.day5State = data[i].weather[0].main;
        this.day5Temp = Math.round(data[i].main.temp);

      }

I'v try to google it, but with no results for reasonable explanation. Can someone explain its behavior. Thanks :)

  • [What is the !! (not not) operator in JavaScript?](https://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript) – Lars Beck Jun 11 '18 at 10:35

1 Answers1

4

!! represents a double negation, you're basically calling the not operator twice.

It's useful if you want to force a cast from any type to a boolean

e.g.

var somethingTruthy = {};
somethingTruthy = !!somethingTruthy //force cast to boolean
console.log(somethingTruthy); //print true

or

var somethingFalsy = "";
somethingFalsy = !!somethingFalsy //force cast to boolean
console.log(somethingFalsy); //print false
Karim
  • 8,454
  • 3
  • 25
  • 33