What is a constructor to create String object in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To create a String object in JavaScript, use string.constructor. A constructor returns a reference to the string function that created the instance's prototype.


You can try to run the following code to create a String object with the constructor −

Live Demo

      <title>JavaScript String constructor Method</title>

         var str = new String( "This is string" );
         document.write("str.constructor is:" + str.constructor);
Updated on 15-Jun-2020 07:09:25