I am trying to compare using the following below formats :
var u=new String('test');
var t=new String('test');
When i check (u==t) or (u===t) it returns false.
Similarly if I try to do
var u=new String();
var t=new String();
u='test';t='test';
Now (u==t) and (u===t) returns true.
Stringconstructor are objects and objects cannot be compared in JS. The last two are created as object and then overwritten by String, so it works.new Stringinstances, are compared by their identity and that's different for everynewinstance created. So, 2 distinct object can never be equal. Primitives, as you're using the 2nd example (the objects are replaced, not modified), are compared by their values.