{"id":893,"date":"2022-08-30T15:08:56","date_gmt":"2022-08-30T15:08:56","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/property-value-of-a-string-object-in-javascript-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:08:56","modified_gmt":"2022-08-30T15:08:56","slug":"property-value-of-a-string-object-in-javascript-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/property-value-of-a-string-object-in-javascript-collection-of-common-programming-errors\/","title":{"rendered":"Property value of a String object in JavaScript-Collection of common programming errors"},"content":{"rendered":"<blockquote>\n<p>There are two different types of Strings and the behave quite differently. A literal is created just by using quotes around your string. An object is created by implicit use of the new keyword. If you assign a string to a variable using the String keyword, without the new keyword the contents of the parenthesis will be cast as a string literal.<\/p>\n<p>A string literal has access to all of a string&#8217;s objects and methods because javascript will temporarily cast a string literal as a string object in order to run the desired method.<\/p>\n<p>Where the two differ is their treatment of new properties and methods. Like all Javascript Objects you can assign properties and methods to any String object.<\/p>\n<p>You can not add properties or methods to a string literal. They are ignored by the interpreter.<\/p>\n<p>The reason you can&#8217;t add properties or methods to a string literal is that when you try to access a literal&#8217;s property or method, the Javascript interpreter temporarily copies the value of the string into a new object and then use that object&#8217;s properties or methods. This means a String literal can only access a string&#8217;s default properties or methods and those that have been added as prototypes.<\/p>\n<\/blockquote>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:55:21. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>There are two different types of Strings and the behave quite differently. A literal is created just by using quotes around your string. An object is created by implicit use of the new keyword. If you assign a string to a variable using the String keyword, without the new keyword the contents of the parenthesis [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-893","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=893"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/893\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}