There are actually two ways in which strings can be made in javascript.
var str = 'Javascript';
This creates a primitive string value.
var obj = new String('Javascript');
This creates a wrapper object
of type String
.
typeof str // string
typeof obj // object
So the best way to check for equality is using the ===
operator because it checks value as well as type of both operands.
If you want to check for equality between two objects then using String.prototype.valueOf
is the correct way.
new String('javascript').valueOf() == new String('javascript').valueOf()