0

I was just working around with number and string and found Expected behavior of javascript.

new String("a") == "a" returns true while new String("a") == new String("a") returns false

Same applies with Number

new Number(7) == new Number(7) returns false

Please Someone explain me why this is happening

Thanks in advance.

Chetan
  • 944
  • 5
  • 22
  • 2
    Did you mean `new String("a") == new String("a")` returns _`false`_? – Sebastian Simon Nov 23 '16 at 04:27
  • 1
    `new` creates an Object, every Object occupies its own memory space, so comparing two `objects` will return `false`, in the first case, Object is treated as `string "a"` so its equal with `string literal "a"` – Rajesh Dan Nov 23 '16 at 04:30
  • Another dupe target: [Why does (“foo” === new String(“foo”)) evaluate to false in JavaScript?](http://stackoverflow.com/q/10951906/4642212). – Sebastian Simon Nov 23 '16 at 04:30
  • yes @Xufox it returns false – Chetan Nov 23 '16 at 04:49

0 Answers0