A JavaScript string is a sequence of text characters used for values such as names, messages, URLs, labels, and user input. Strings can be written with single quotes, double quotes, or template literals.
const name = "plus2net";
const message = `Welcome to ${name}`;
console.log(message); // Welcome to plus2net
JavaScript strings are immutable: methods return new strings rather than changing the original text in place.
Single and double quotes create ordinary string literals. Template literals use backticks and are especially useful for interpolation and multiline text.
const first = 'JavaScript';
const second = "String";
const topic = `${first} ${second}`;
console.log(topic);
Most code should use string primitives such as "hello". JavaScript temporarily exposes String methods on primitive values, so you normally do not need new String(). See the JavaScript String object tutorial for the difference.
Use length to count UTF-16 code units. Use charAt() or bracket access for positions, and charCodeAt() when you need a UTF-16 code-unit value.
const text = "JavaScript";
console.log(text.length); // 10
console.log(text.charAt(0)); // J
console.log(text[0]); // J
Use indexOf() when you need a numeric position. Use includes() for a simple true/false test. Use search() when a regular expression is useful.
slice() and substring() extract ranges. The older substr() page is retained for legacy-code understanding, but new code should generally prefer slice() or substring().
Strings themselves do not change; methods return new values. Explore toUpperCase(), toLowerCase(), replace(), concat(), and the string reverse examples.
JavaScript string indexes and length operate on UTF-16 code units. Some Unicode characters can therefore occupy two string positions. The String.fromCharCode() and charCodeAt() tutorials explain code units; modern Unicode code-point handling can use codePointAt() and String.fromCodePoint().
Older JavaScript exposes methods such as bold() and link(). These HTML wrapper methods are legacy features; modern pages should create semantic HTML with markup or DOM APIs and use CSS for presentation. The old tutorials remain useful when maintaining historical code.
The older escape() / unescape() topic is also retained for legacy reference. For URL components, modern JavaScript normally uses encodeURIComponent() and decodeURIComponent().
| Tutorial | What it teaches |
|---|---|
| String object | Primitive strings, String objects, methods, immutability and legacy wrappers. |
| length | String length, indexes, empty strings and Unicode considerations. |
| charAt() | Read a UTF-16 code unit at a zero-based position. |
| charCodeAt() | Get a UTF-16 code-unit number. |
| String.fromCharCode() | Create text from UTF-16 code units. |
| concat() | Combine strings and compare with + and template literals. |
| indexOf() / lastIndexOf() | Find the position of text. |
| search() | Search with strings or regular expressions. |
| slice() | Extract text with start/end indexes, including negative indexes. |
| substring() | Extract text between start and end indexes. |
| substr() | Understand legacy start-plus-length extraction. |
| replace() | Find and replace text. |
| toUpperCase() / toLowerCase() | Change letter case. |
| Email user/domain example | Combine index and extraction methods on an email-like value. |
| onblur text case example | Apply string methods after a form field loses focus. |
0.length always equals the number of user-perceived Unicode characters.new String() when a primitive string is sufficient.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.