0
var str1 = "Sagar"; //String literal
var str2 = new String("Sagar"); //String Object
str1.length; // Output: 5
str2.length; // Output: 5

/* How is it possible for a string literal like in str1 variable to access the properties and methods? */

  • Because a string literal is an object of type String. What did you think they were? – Tim Roberts Apr 08 '22 at 06:48
  • Okay. I know that the string literal is an object of type String. But how javascript knows the difference between the string literal and string object. – Modu Sagar Kumar Apr 08 '22 at 06:56
  • Please check the duplicates mentioned at the top. – adiga Apr 08 '22 at 06:59
  • There ISN"T a difference. A string does not exist as a string. Javascript simply does not have that concept. A string literal implicitly creates an object of type String. – Tim Roberts Apr 08 '22 at 22:48

0 Answers0