17
makmm
3y

JS you drunk?

Comments
  • 6
    Kill me
  • 4
    JS: ...what you talkin' 'bout. I'm always drunk. You?
  • 12
    They are equal but they are not the same. JS is doing the right thing here.
  • 2
    Try === . I think you are drunk lol
  • 1
    @sandipsubedi that's generally a good idea, but wouldn't change a thing in this case. With strict comparison the typecasting is not happening. In this case they both are objects, so the result will be the same.
  • 16
    You are actually comparing 2 different references to 2 different objects, which obviously returns false. Objects in js are only equal to themselves:
    var a = {}
    a == a //returns true
  • 2
    @Rayne exactly.
  • 0
    "==" is used to compare values. These are objects
  • 1
    @Olverine and objects are not values? That's wrong. You absolutly can check an object, if it's the same as in another variable.
  • 1
    @plusgut Yes, you are right! Forgive me!
  • 0
    @Olverine no problem ;)
  • 1
    So then === should work?
  • 3
    @makmm no. As I said before, tripple equals are generally a good idea. But the only difference is, that it's a type-secure comparison. Since your comparison both sides have the same type "object", the result will be the same.

    But there are libraries, e.g. underscore/lodash which give you an _.equal method, where you can check if the objects are equal to each other.
  • 1
    @plusgut @plusgut oml not another library
  • 1
    @makmm you can try to implement it yourself, but you will have some issues with objects like date and so on.

    But it's generally not a good idea to compare to objects, other then for testing purpose.
  • 1
  • 0
    @makmm especially when it comes to the prototype properties, how should the equal check be implemented. Should it check only the values which it has by its own. Or should it look up the prototypechain?

    And because there is no clear answer, but only different usecases, it's a bad idea to compare to objects. The only useful thing is, to check if it's actually the same object.
  • 3
    This is expected behaviour. {} is a reference. It's the same reason one wouldn't use == in Java to test string equality.
  • 2
    Also in Java new Object() == new Object() is false. I think people should study a bit of a language before complain lol
  • 3
    It's a fucking joke, chill.
  • 0
    JS in case of objects and array works on the concept of reference variable and what you see up there is actually the desired response.
  • 0
    @makmm are you drunk?
    Good luck with your internship
  • 1
    @theScientist do you have any questions as well?
  • 2
    @MasterSwagMan why are you so rude?
  • 0
  • 0
    @ThatDude ah okay, I disagree
  • 0
    If you want to check if it return object you can always do this
    typeof(_refrenceToObject) === "object"
    Or
    _refrenceToObject instanceOf Object

    Or to check if its empty object
    if(!_refrenceToObject) // if(!xhr)
  • 0
    And as someone has already mentioned why this return false, this behavior is justified and not a bug or issue. You actually are comparing two different object. Though there are work around for this as I had mentioned in my previous comment.

    Like if you declare
    Let a = {}
    Let B = {}

    As any noobie would think, a=B, but it's actually not.
    Think it as
    Let a = new Object() // let B
    You are creating new instance of object every time
  • 0
    @chiragiem36 be careful when you are checking typeof of an object, the value 'null' is from the type of object.
    The check for an empty object is wrong, this way you are checking if the variable has a falsey value. (e.g. false, null, undefined, ...)
    If you want for an empty object, you should as for the properties it has. With Object.keys(_refrenceToObject)
  • 2
  • 0
    @plusgut damn my short term memory.
    But this will work
    if(!reference && typeof refrence === "object")
  • 1
    PLEASE STOP LMAO I LEARNED SOMETHING NOW STOP
  • 1
    @theScientist yes but pepole on here sometimes just keep bullshitting with stuff that won't be used in a real world scenario....
  • 1
    @makmm why whould we shut up? Some interesting points are being discussed
  • 0
    @plusgut now he had lost all the rights to call JS drunk
  • 1
    @plusgut there's multiple other places where you can discuss... You are spamming me with notifs right now...
  • 0
    @makmm what would not be considered as spam here ?
  • 1
    @chiragiem36 @chiragiem36 I didn't say it's spam... I'm saying that it's spamming (flooding, filling, whatever) my notifs
  • 0
    @chiragiem36 nah, there are many reasonsto call js out on it's shit. That typeof(null) goes as an object, is one of them.
  • 2
    @makmm you made a provocative statement,what did you expect to happen?
    And as far as I can see, each post is at the topic.
  • 0
    @plusgut well actually null is an object ..Empty object
  • 1
  • 1
    @chiragiem36 that's correct, but it should have been it's own type. Like function has the typeof 'function', but is an object. And there was a changerequest for the language, but they didn't do it because of backward compatibility.
  • 0
    @plusgut true .... It's confusing for newbies
  • 1
    FFS i'm on devRantron and I can't disable notifs @Dacexi
  • 1
    also @Dacexi the height problem is fixed thanks!!
  • 2
    @makmm now you are actually spammy yourself and not being on topic ;)
  • 1
    @plusgut I'm asking how to disable notifs from this rant, so I fucking stop annoying you. Can you stop fucking arguing, when I'm trying to fucking help you? ffs.
  • 1
    @makmm where there is a problem, there's an opportunity
  • 1
    @chiragiem36 @chiragiem36 >.>
  • 0
    @chiragiem36 what is in your opinion: is typeof(null) === 'object' is confusing? I would agree.
    typeof(null) === 'null' I would say that's declarative. undefined function and so on behave the same way.
  • 0
    @makmm you are trying to help me?
    I don't need no help from you.
  • 0
    @makmm see ...You are tagging me twice now
  • 1
    @chiragiem36 @plusgut fuck it i'm not arguing with you anymore
  • 0
    @plusgut that means you need some help?
  • 0
    @makmm Damn ...No more entertainment
  • 0
    @chiragiem36 yes, I need reinforcment for my team with capable js developers.
  • 1
    @chiragiem36 @plusgut you are the cancer of devRant. fuck off.
  • 1
    @makmm why so rude? I disagree.
  • 1
    @plusgut @plusgut. You are
    1. Making fun of my english skillz (that are not much lmfao)
    2. being offtopic
    3. making fun of me when i'm letting you be offtopic.
    ffs. Please, stop.
  • 1
    @chiragiem36 I'm double tagging you cus devrantron HAD this bug where it wouldnt tag you
  • 1
    Also, I wouldn't be annoyied if it wasn't on devRant. But devRant is a place that is _supposed_ to not have trolls...
  • 1
    @makmm when did I make fun of you at all?
    1. My english skills myself aren't good, why would I make fun of yours?
    2. I was just answering questions and correct wrong statements.
    3. I didn't make fun of you at all. Please quote where I did something like that.
  • 0
    @makmm "making fun of your English" .... Which part of conv. bring your brain here dude ?
  • 2
    @chiragiem36
    > @plusgut that means you need some help?
    > @makmm Damn ...No more entertainment
  • 1
    @plusgut
    > @chiragiem36 yes, I need reinforcment for my team with capable js developers.
  • 1
    also "makmm mentioned you in a comment" :P
  • 1
    @makmm where exactly made I fun about you? I don't see what upsetting you there at all. I didn't attack you in any way.
  • 2
    @makmm if you find any bugs please report them over at https://github.com/tahnik/... although a lot of issues have been fixed in the latest update we're working on 🙂
  • 0
    @Dacexi I can't see job posting by devRant. Please fix this bug
  • 2
    @Dacexi Okay thanks, sorry
    i'ma bookmark it
  • 2
    @jalebiBhai "job posting" i'm guessing you're talking about collabs. If you go tho the sidebar theres a "Collabs" button. If that does not work for some reason please post an issue over at https://github.com/tahnik/...

    Also make sure you're running the latest version of devRantron which is v1.3.9. You can check which version you're running in the bottom of the settings page.
Add Comment