Strings · 문자열
Strings are text
- A string is text inside quotes:
"Ada"or'Ada'. - Join strings with
+— this is called concatenation.
문자열은 텍스트입니다
- 문자열은 따옴표 안의 텍스트입니다:
"Ada"또는'Ada'. +로 문자열을 연결합니다 — 이를 **연결(concatenation)**이라고 합니다.
let first = "Ada";
console.log("Hi, " + first + "!"); // → Hi, Ada!
Mind the spaces
+joins text exactly. It never adds a space for you.- Put the space inside the quotes, where you want it to appear.
공백에 주의하십시오
+는 텍스트를 정확히 결합합니다. 자동으로 공백을 추가하지 않습니다.- 원하는 위치에 공백이 나타나도록 따옴표 안에 공백을 넣으십시오.
let pet = "Rex";
console.log("Good dog," + pet + "!"); // → Good dog,Rex! (no space)
console.log("Good dog, " + pet + "!"); // → Good dog, Rex!
Length and capitals
.lengthcounts the characters..toUpperCase()and.toLowerCase()return a copy in CAPITALS or small letters.
길이와 대소문자
.length는 문자의 개수를 세어 줍니다..toUpperCase()과.toLowerCase()은 대문자 또는 소문자로 변환된 복사본을 반환합니다.
console.log("hello".length); // → 5
console.log("hello".toUpperCase()); // → HELLO
Index and slice a string · 문자열의 인덱싱 및 슬라이스
Characters are numbered from 0. A slice takes from start up to — but not including — end. · 문자들은 번호가 0부터 시작합니다. 슬라이스는 start부터 시작하여 — 포함하지 않고 — end까지 가져옵니다.
Reach inside a string
- Each character has a position, counting from 0:
text[0]is the first one. .slice(start, end)takes the part fromstartup to — but not including —end.
문자열 내부에 접근하기
- 각 문자는 0부터 시작하는 위치를 가지며, 이 중
text[0]이 첫 번째 위치입니다. .slice(start, end)은start부터 시작하여 — 하지만 포함하지 않고 —end까지의 부분을 가져옵니다.
let word = "JAVASCRIPT";
console.log(word[0]); // → J
console.log(word.slice(0, 4)); // → JAVA
Watch out
- Positions start at
0, so the 4th character isword[3]. - String methods return a new string — the original never changes.
주의사항
- 위치는
0에서 시작하므로, 4번째 문자는word[3]입니다. - String 메서드는 새로운 문자열을 반환합니다. — 원본은 절대 변경되지 않습니다.
Common mistakes
- Index from
0;s.lengthis a property (no()). - Strings cannot be changed in place.
흔한 실수
- 인덱스는
0부터 시작하며,s.length은 속성입니다(()는 없습니다). - 문자열은 위치를 변경할 수 없습니다.
Now you try
- Build and inspect strings.
- Press Check answer to test it.
이제 직접 해보기
- 문자열을 생성하고 확인하세요.
- 답안 확인을 눌러 테스트해 보십시오.
let name = "Sam". Use + to log Hello, then the name then !, so it reads Hello, Sam!. · let name = "Sam". +을 사용하여 Hello, 을 출력한 뒤 이름과 !을 출력하여, 결과가 Hello, Sam!이 되도록 만듭니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Log how many characters are in the string computer using .length (it is 8). · computer이라는 문자열에 포함된 문자의 개수를 .length을 사용하여 출력합니다(그 결과는 8입니다).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Log the string cat in CAPITALS using .toUpperCase() (it is CAT). · cat이라는 문자열을 대문자로 .toUpperCase()을 사용하여 출력합니다(그 결과는 CAT입니다).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
let word = "code". Log just its first letter using word[0] (it is c). · let word = "code". word[0]을 사용하여 오직 첫 글자를 출력합니다(그 결과는 c입니다).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.