you are viewing a single comment's thread
view the rest of the comments
[–] 2 points 1 year ago (6 children)

But then why 2 == true if true is converted to 1

  • source
  • hideshow 6 child comments
  • [–] 8 points 1 year ago (4 children)

    It's not. Just tried in my Browser Console:

    2 == true // returns false
    
  • source
  • parent
  • hideshow 4 child comments
  • [–] 6 points 1 year ago (3 children)

    I genuinely wasn't aware of that. I must be getting javascript confused for almost any other language. I wonder how many times ive !!'d a value to make that work without actually absorbing that into my head now..

  • source
  • parent
  • hideshow 3 child comments
  • [–] 3 points 1 year ago (1 child)

    In other languages that shouldn't be equal either though, right?

    Maybe you meant

    if (2){
    console.log("nonzero ints are truthy")
    }
    else {
    console.log("no they're not")
    }
    

    Which would output

    nonzero ints are truthy
    

    and that would actually work in all languages I know. But that's different from being equal.

  • source
  • parent
  • hideshow 1 child comment