1

As, I learnt these are the ways of making a string. However , the string made using new keyword give us a object and and array as well.

The output given by string made using new keyword:

                    String {'ashim kandel'

0: "a" 1:"s" 2: "h" 3:"i" 4:"m" 5: "" 6: "k" 7: "a" 8: "n" 9: "d" 10: "e" 11: "l" length: 12 [[Prototype]]: String [[PrimitiveValue]]: "ashim kandel"

However , the string made with String constructor gives us string .

//here is the code

const strPrim3 = String('ashim kandel'); // Coerced into the string primitive "true"

const strObj = new String('ashim kandel); // String with new returns a string wrapper object.

//please tell me how things are working here

  • you only notice the difference if you check the variables type with `typeof` or when you compare values, `(strObj == 'ashim kandel')` gives TRUE, `(strObj === 'ashim kandel')` gives FALSE; while both `(strPrim3 == 'ashim kandel')` and `(strPrim3 === 'ashim kandel')` give TRUE https://jsfiddle.net/ev6zx58h/ – GrafiCode Oct 09 '22 at 11:39
  • Refer MDN documentation [String primitives and String objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_primitives_and_string_objects) – Wazeed Oct 09 '22 at 12:19

0 Answers0