-1

I understand the use of ! when we are implementing it in code like != or !== etc But I'm just wondering what it means when it is put before something like if(!arr[i]){"do this}

thank you

de19
  • 61
  • 7

1 Answers1

1

! means "not." It means this in each of these contexts. != is not equal. !(arr[i]) means when arr[i] does not equate to true.

STF_ZBR
  • 395
  • 1
  • 12
  • 1
    This is not correct, !(arr[i]) means the contents of the array at that position has a falsey value which could be undefined, 0, NaN, null, '' empty string etc. Any truthy value, not just true will mean the statement is falsey. A non zero number, non empty string and true etc. – Adrian Brand Jun 17 '20 at 01:15
  • A falsey value would not equate to true. A value of true would not be falsey. I understand your position, but notice I used "equate" rather than equal. In the situation of the if statement it would equate to true or it would not. – STF_ZBR Jun 17 '20 at 01:18
  • The question is all about what values in the array will make the if statement execute the block. Your answer is not equal to true, but that is not correct. It is any falsey value at position i in the array will "do this" – Adrian Brand Jun 17 '20 at 01:23