top 50 comments

sorted by: hot top controversial new old
[–] 73 points 2 years ago* (1 child)
  • [+] 19 points 2 years ago (6 children)
  • [–] 7 points 2 years ago (1 child)

    almost forced to for web front end. why you would use it anywhere else, however, i will never know

  • source
  • parent
  • hideshow 2 child comments
  • [–] 4 points 2 years ago

    The same reason people drive their car to buy groceries.

    You bought it for something where it was the only option, driving 30km to work everyday. But ever since you got it, the trip to the super market is kinda too hot in the summer and too cold in the winter and what if you spontaneously need to buy more than expected?

    People learn it for front end dev, and then they use what they know for back end too.

  • source
  • parent
  • load more comments (1 reply)
  • [–] 46 points 2 years ago* (last edited 2 years ago) (11 children)

    I still don't understand the === operator

    Edit: I think a more type strict ==? Pretty sure I understand the point of typescript now.

  • source
  • hideshow 21 child comments
  • [–] 126 points 2 years ago* (1 child)

    So in JavaScript there’s the assignment

    =
    

    and the comparator is

    ==
    

    Since there’s no types JS will do implicit conversion before comparison when using == in a case like this

    if(false == '0'){
        //this is true
    }
    

    But with === it doesn’t. It means literally compare these

    if(false === '0'){
        //this is false
    }else{
        //so this will execute instead 
    }
    

    But this, however, will

    var someState = false;
     if(someState === false){
        //this is true
    }
    
  • source
  • parent
  • hideshow 2 child comments
  • [–] 19 points 2 years ago (1 child)

    JS's == has some gotchas and you almost never want to use it. So === is what == should have been.

    All examples are true:

    "1" == true
    [1, 2] == "1,2" 
    " " == false
    null == undefined 
    

    It isn't that insane. But some invariants that you may expect don't hold.

    "" == 0
    "0" == 0
    "" != "0" 
    
  • source
  • parent
  • hideshow 2 child comments
  • [–] 18 points 2 years ago* (2 children)

    It's also important if you're checking hashes (at least, it was - if you're using correct hashing algorithm that isn't ancient, you will not have this problem).

    Because if you take for example "0e462097431906509019562988736854" (which is md5("240610708"), but also applicable to most other hashing algorithms that hash to a hex string), if("0e462097431906509019562988736854" == 0) is true. So any other data that hashes to any variantion of "0e[1-9]+" will pass the check, for example:

    md5("240610708") == md5("hashcatqlffzszeRcrt")

    that equals to

    "0e462097431906509019562988736854" == "0e242700999142460696437005736231"

    which thanks to scientific notation and no strict type checking can also mean

    0^462097431906509019562988736854^ == 0^242700999142460696437005736231^

    which is

    0 == 0 `

    I did use md5 as an example because the strings are pretty short, but it's applicable to a whole lot of other hashes. And the problem is that if you use one of the strings that hash to a magic hash in a vulnerable site, it will pass the password check for any user who's password also hashes to a magic hash. There's not really a high chance of that happening, but there's still a lot of hashes that do hash to it.

  • source
  • parent
  • hideshow 3 child comments
  • load more comments (1 reply)
  • [–] 6 points 2 years ago (1 child)

    The other comments explains it in pretty good detail, but when I was learning my teacher explained it sort of like a mnemonic.

    1 + 1 = 2 is read "one plus one equals two"

    1 + 1 == 2 is read "one plus one is equal to two"

    1 + 1 === 2 is read "one plus one is really equal to two"

    And you hit the nail on the head, is that === is type explicit while == is implicit.

  • source
  • parent
  • hideshow 2 child comments
  • load more comments (1 reply)
    [–] 13 points 2 years ago

    JS devs should have a font that turns == into ≈.

  • source
  • [–] 12 points 2 years ago (3 children)

    I wish the assignment operator wasn’t the equal sign.

  • source
  • hideshow 5 child comments
  • [–] 19 points 2 years ago (2 children)
  • load more comments (1 reply)
    [–] 11 points 2 years ago (1 child)
  • [–] 11 points 2 years ago* (3 children)
    load more comments (3 replies)
    [–] 10 points 2 years ago* (1 child)
  • [–] 7 points 2 years ago (1 child)

    it depends on what your definition of is is

  • source
  • hideshow 1 child comment
  • load more comments (1 reply)
    [–] 5 points 2 years ago (1 child)
    load more comments (1 reply)
    [–] 4 points 2 years ago (3 children)

    Mathematica also has an === operator. And :=.

  • source
  • hideshow 4 child comments
  • load more comments (2 replies)
    [–] 4 points 2 years ago (2 children)

    As a backend developer i still dont know a shit what that means

  • source
  • hideshow 4 child comments
  • load more comments
    view more: next ›