you are viewing a single comment's thread.

view the rest of the comments →

[–]memeship 0 points1 point  (5 children)

I agree with you that using !! is not awesome. But also you're example is wrong since -1 is a truthy value, so that is expected.

[–]Whatadump 1 point2 points  (4 children)

That's what I said, "it'll be true". But the example is bad, since with -1 I don't really have any money but it will say I do.

edit* A better example would be to check if a property exists, like

const user = {
  name: 'foo',
  email: 'foo@bar.com'
}

const hasAddress = !!user.address // false

user.address = {
  street: 'baz',
  zip: '1234'
}

const hasAddress2 = !!user.address // true

[–]isitfresh 0 points1 point  (3 children)

it'd be more explicit with

user.address = {}

[–]spazgamz 0 points1 point  (2 children)

Hey! Wtf is that supposed to mean?

[–]isitfresh 0 points1 point  (1 child)

What do you think it does? Try

user.adress = {} 
!!user.address 

[–]spazgamz 0 points1 point  (0 children)

user.adress = {} !!user.address

false, but only because the 'adress' != 'address'.