JavaScript provides a built-in String type for working with text. In normal application code, use string primitives such as "Welcome"; JavaScript still lets you call String methods on those primitive values.
const message = "Welcome to plus2net.com";
console.log(message.length);
console.log(message.toUpperCase());
Avoid creating wrapper objects with new String() unless you specifically need to study wrapper-object behavior.
String literals are primitive values and are the normal way to store text.
const site = "plus2net.com";
console.log(typeof site); // "string"
The original page created a String object like this. It still works, but the result is an object rather than a primitive string.
const myString = new String("Welcome to plus2net.com");
console.log(typeof myString); // "object"
Calling String() without new is useful for converting another value to text.
const count = 42;
const text = String(count);
console.log(text, typeof text); // "42" "string"
Methods return new strings. They do not edit the original string value.
const original = "javascript";
const upper = original.toUpperCase();
console.log(original); // javascript
console.log(upper); // JAVASCRIPT
The original page demonstrated the length property. It counts UTF-16 code units.
const myString = "Welcome to plus2net.com";
console.log(myString.length); // 23
Other frequently used methods include toUpperCase(), toLowerCase(), includes(), indexOf(), slice(), substring(), replace(), trim(), startsWith() and endsWith().
const primitive = "hello";
const objectValue = new String("hello");
console.log(primitive === objectValue); // false
console.log(primitive === objectValue.valueOf()); // true
The original tutorial demonstrated methods such as bold(), fontsize(), blink(), fixed(), fontcolor(), italics(), link(), strike() and sub(). These are legacy HTML wrapper methods and should not be used to build modern interfaces.
const text = "Hello";
console.log(text.bold()); // legacy: returns an HTML wrapper string
Use semantic HTML/DOM APIs and CSS instead. The legacy strike method example remains available for maintaining old code.
The original String-object page also demonstrated substring extraction. Modern primitive strings support the same String prototype methods.
const myString = "Welcome to plus2net.com";
console.log(myString.substring(11, 19)); // plus2net
See substring() and slice() for the full extraction rules.
JavaScript strings are indexed as UTF-16 code units. Basic Latin characters normally occupy one code unit, while some Unicode symbols use a pair. For those cases, codePointAt(), String.fromCodePoint(), spread syntax, or Array.from() can be more appropriate than processing one code unit at a time.
new String() for ordinary text values.length always counts user-perceived Unicode characters.String Reference Uppercase Strings
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.