6
sheddy
6y

First stage of burn out 😂 😂 😂

Comments
  • 0
    What's !! do?
  • 1
    @Proximyst in JS the first ! coerces the value into a boolean and then, the second ! Inverts that boolean

    What i really mean is you use it to turn something into a boolean, eg
    "test"
    !"test" // false
    !!"test" // true

    So you turn a "falsy" value into false and a "truthy" value into true
  • 0
    @ObiSwagKenobi Why not just check if it's truthy then? (Just checking the variable)
  • 1
    @Proximyst well it certainly makes the code a lot more readable. If you see a !! you know it's either true or false.

    when you're creating an api,let's say for your team, you want your functions to be explicit in what they return. Let's say you have a

    const hasUsername = user => !!user.email

    It's better to return true or false rather than relying to the other person to check for null/undefined/empty string etc

    Not the best example but I hope you get the point 😁
  • 0
    @ObiSwagKenobi In an if statement, that is pretty clear, though
  • 0
Add Comment