on
15. Javascript Strings and more
15. Javascript Strings and more
* Udemy "The Web Developer Bootcamp 2021"(by. Colt Steele)의 강의내용을 정리
152. Introducing Strings
- Strings represent text, and must be wrapped in qoutes.
- Double and single qoutes both work, but never mix those two!
153. Indices & Length
- Each character of string has a corresponding index (a positional number) just like array.
- String has property of length.
let animal = "Dumbo" animal[0] // "D" animal[1] // "u" animal[4] // "o" animal.length // 5
- If you try to combine string and number, JS will convert number into string. (There is a specific rule for this kind of type-changing)
154. String Methods
- Methods are built-in actions we can perform with individual data type.
- Methods have parentheses. (str.length is not a method! It's an property)
- toUpperCase(), toLowerCase(), trim(), etc...
155. String Methods With Arguments
- Some methods accept arguments that modify their behavior.
- Arguments are kind of input that we can pass into the methods.
/*indexOf()*/ let tvShow = "American Hero" tvShow.indexOf("American") // 0 tvShow.indexOf("Hero") // 9 /*slice()*/ let chant = "Youwillneverwalkalone" chant.slice(0, 3) // "You" chant.slice(3) // "willneverwalkalone" /*replace()*/ let str = "haha so funny haha" str.replace("haha", "lol") // "lol so funny haha" // it only replace the first instance
156. String Template Literals
- use `` to combine string and an object!
from http://oaat9309.tistory.com/27 by ccl(A) rewrite - 2021-11-03 21:02:33