0

What does !varName mean?

I tried it out by doing the following:

var varName = "string"
console.log(!varName)

Console printed "false". What does this mean?

  • This means that the `type` of ```String``` is not equal to true. :) check out these docs on falsy values https://developer.mozilla.org/en-US/docs/Glossary/Falsy – Sweet Chilly Philly Oct 06 '20 at 03:23
  • @SweetChillyPhilly I thought since the string is not empty, it should be true, no? –  Oct 06 '20 at 03:42
  • @apricotzlover `!` is negation. When a string is not empty, it is considered as a truthful value, so when cast into boolean, the javascript interpreter will look it as `!"string"` -> `!true` -> `false`. – Jamie Phan Oct 06 '20 at 04:26
  • @JamiePhan that was so silly of me, thanks –  Oct 06 '20 at 06:18

0 Answers0