Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
This post is part of a series called JavaScript Succinctly.
Working With Objects and Properties

The String() constructor function is used to create string objects and string primitive values.

In the following sample, I detail the creation of string values in JavaScript.

Sample: sample47.html

String() Parameters

The String() constructor function takes one parameter: the string value being created. In the following sample, we create a variable, stringObject, to contain the string value "foo".

Sample: sample48.html

When used with the new keyword, instances from the String() constructor produce an actual complex object. You should avoid doing this (use literal/primitive numbers) due to the potential problems associated with the typeof operator. The typeof operator reports complex string objects as 'object' instead of the primitive label ('string') you might expect. Additionally, the literal/primitive value is just faster to write and is more concise.

String() Properties and Methods

The String object has the following properties and methods (not including inherited properties and methods):

Properties (e.g., String.prototype;)

Methods (e.g., String.fromCharChode();)

String() Object Instance Properties and Methods

String object instances have the following properties and methods (not including inherited properties and methods):

Instance Properties (e.g., var myString = 'foo'; myString.length;)

Instance Methods (e.g., var myString = 'foo'; myString.toLowerCase();)


So that details the process of creating a string using the String() constructor, its methods and properties.

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.