---
id: javascript-string-methods
title: "JavaScript String Methods"
category: "Frontend"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["string methods", "slice", "substring", "trim", "replace", "split", "padStart"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.88
created_at: 2026-06-23
updated_at: 2026-06-23
review_reason: ""
merge_history: []
tags: ["javascript", "js", "web", "frontend", "w3schools", "strings", "string-methods", "immutability"]
raw_sources: ["https://www.w3schools.com/js/js_string_methods.asp"]
applied_in: []
github_commit: ""
---

# [[JavaScript String Methods]]

## 🎯 한 줄 통찰 (One-line insight)
Strings are immutable, so every string method produces a new string without altering the original — covering extraction (`slice`, `substring`, `substr`), character access (`charAt`, `at`, `[]`), case, trimming, padding, and replacement. [S1]

## 🧠 핵심 개념 (Core concepts)
- **Immutability** — all string methods produce a new string without altering the original string; strings cannot be changed, only replaced. [S1]
- **`length`** — the `length` property returns the length of a string. [S1]
- **Character extraction** — four ways to get a character: `at()`, `charAt()`, `charCodeAt()`, and bracket notation `[]`; `codePointAt()` returns a code point. [S1]
- **`at()` allows negative indexes** — introduced in ES2022, `at()` allows negative indexes while `charAt()` does not. [S1]
- **Substring extraction** — `slice()`, `substring()`, and `substr()` extract parts of a string; `substr()` is deprecated. [S1]
- **`replace()` vs `replaceAll()`** — `replace()` replaces only the first match and is case sensitive by default; `replaceAll()` (ES2021) replaces all matches. [S1]
- **`split()`** — converts a string into an array using a chosen delimiter. [S1]

## 🧩 추출된 패턴 (Extracted patterns)
- **Extract a slice by index range** — `text.slice(start, end)` (or `substring`) to pull a labeled portion. [S1]
- **Normalize input** — chain `trim()` / `trimStart()` / `trimEnd()` then case methods to clean user input. [S1]
- **Pad to a fixed width** — `padStart(len, "0")` to left-pad values such as IDs or amounts. [S1]
- **Replace all occurrences** — `replaceAll(a, b)`, or `replace()` with a `/g` regex flag, since plain `replace()` only hits the first match. [S1]

## 📖 세부 내용 (Details)
> Note: All string methods produce a new string without altering the original string. Strings are immutable: strings cannot be changed, only replaced. [S1]

**Length** [S1]
```javascript
let text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let length = text.length;
```

**charAt()** — returns the character at a given index. [S1]
```javascript
let text = "HELLO WORLD";
let char = text.charAt(0);
```

**charCodeAt()** — returns the UTF-16 code of the character at a given index. [S1]
```javascript
let text = "HELLO WORLD";
let char = text.charCodeAt(0);
```

**codePointAt()** — returns the Unicode code point at a given index. [S1]
```javascript
let text = "HELLO WORLD";
let code = text.codePointAt(0);
```

**at()** — introduced in ES2022; allows negative indexes while `charAt()` does not. [S1]
```javascript
const name = "W3Schools";
let letter = name.at(2);
```

**Property access []** — bracket notation reads a character by index. [S1]
```javascript
let text = "HELLO WORLD";
let char = text[0];
```

**concat()** — joins two or more strings. [S1]
```javascript
let text1 = "Hello";
let text2 = "World";
let text3 = text1.concat(" ", text2);
```

**slice()** — extracts a part of a string between start and end positions. [S1]
```javascript
let text = "Apple, Banana, Kiwi";
let part = text.slice(7, 13);
```

**substring()** — similar to `slice()`. [S1]
```javascript
let str = "Apple, Banana, Kiwi";
let part = str.substring(7, 13);
```

**substr()** — deprecated; second parameter is the length to extract. [S1]
```javascript
let str = "Apple, Banana, Kiwi";
let part = str.substr(7, 6);
```

**toUpperCase()** [S1]
```javascript
let text1 = "Hello World!";
let text2 = text1.toUpperCase();
```

**toLowerCase()** [S1]
```javascript
let text1 = "Hello World!";
let text2 = text1.toLowerCase();
```

**trim()** — removes whitespace from both sides. [S1]
```javascript
let text1 = "      Hello World!      ";
let text2 = text1.trim();
```

**trimStart()** — removes whitespace from the start. [S1]
```javascript
let text1 = "     Hello World!     ";
let text2 = text1.trimStart();
```

**trimEnd()** — removes whitespace from the end. [S1]
```javascript
let text1 = "     Hello World!     ";
let text2 = text1.trimEnd();
```

**padStart()** — pads from the start to a given length (ES2017). [S1]
```javascript
let text = "5";
let padded = text.padStart(4,"0");
```

**padEnd()** — pads from the end to a given length (ES2017). [S1]
```javascript
let text = "5";
let padded = text.padEnd(4,"0");
```

**repeat()** — returns a new string with a number of copies. [S1]
```javascript
let text = "Hello world!";
let result = text.repeat(2);
```

**replace()** — the `replace()` method replaces only the first match. By default, the `replace()` method is case sensitive. [S1]
```javascript
let text = "Please visit Microsoft!";
let newText = text.replace("Microsoft", "W3Schools");
```

**replaceAll()** — replaces all matches (ES2021); use a `/g` flag to replace all matches with regular expressions. [S1]
```javascript
text = text.replaceAll("Cats","Dogs");
text = text.replaceAll("cats","dogs");
```

**split()** — converts a string into an array using a delimiter. [S1]
```javascript
text.split(",")    // Split on commas
text.split(" ")    // Split on spaces
text.split("|")    // Split on pipe
```

Other methods listed by the page include `isWellFormed()` and `toWellFormed()`. [S1]

## 🛠️ 적용 사례 (Applied in summary)
The page's own snippets are the canonical applied examples — extracting substrings from `"Apple, Banana, Kiwi"`, padding `"5"` to width 4, replacing `"Microsoft"` with `"W3Schools"`, and splitting on delimiters. No external project/commit applications found in the source.

## 💻 코드 패턴 (Code patterns)
Extract a portion:
```javascript
let part = text.slice(7, 13);
```
Pad to fixed width:
```javascript
let padded = text.padStart(4,"0");
```
Replace every occurrence:
```javascript
text = text.replaceAll("Cats","Dogs");
```

## ⚖️ 모순 및 업데이트 (Contradictions & updates)
`substr()` is noted as deprecated; prefer `slice()` or `substring()`. No other contradictions found in the source.

## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.88
- **중복 검사 결과:** 신규 생성 (New discovery)

## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[JavaScript Tutorial]]
- **관련 개념:** [[JavaScript Strings]], [[JavaScript String Search]], [[JavaScript String Templates]], [[JavaScript Arrays]]
- **참조 맥락:** Referenced whenever transforming, slicing, cleaning, or replacing text values.

## 📚 출처 (Sources)
- [S1] W3Schools — JavaScript String Methods — https://www.w3schools.com/js/js_string_methods.asp

## 📝 변경 이력 (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript String Methods" page (Astra wiki-curation, P-Reinforce v3.1 format).
