DEV Community

Discussion on: (Not) Everything in JavaScript is an Object

Collapse
 
samuraiseoul profile image
Sophie The Lionhart • Edited

Great article.

Remember kiddos,

String("string") == "string";

but

String("string") !== "string";

Collapse
 
bl41r profile image
David Smith • Edited
String("string") == "string";
true
String("string") === "string";
true
String("string") != "string";
false
String("string") !== "string";
false
Enter fullscreen mode Exit fullscreen mode
Collapse
 
samuraiseoul profile image
Sophie The Lionhart

Hrmmm..... I had done basically the same thing in my console when I made my comment, but I had a different result that day. I honestly expected your to be the case but I got what I typed before. I must have had a typo or something. MB

Thread Thread
 
bl41r profile image
David Smith • Edited

I think you forgot the new keyword:

y = "string"
"string"
x = new String("string")
String {0: "s", 1: "t", 2: "r", 3: "i", 4: "n", 5: "g", length: 6, [[PrimitiveValue]]: "string"}
x === y
false
String("string") === "string"
true
new String("string") === "string"
false
typeof(x)
"object"
typeof(y)
"string"
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
samuraiseoul profile image
Sophie The Lionhart

That's most likely it. You're far more knowledgeable than me in this area it seems. Thanks for adding the clarity for future readers and teaching me something!