본문 바로가기

Develop/JavaScript4

Uncaught TypeError: Cannot read property 'split' of undefined const address = undefined; // ✅ Provide fallback empty string if falsy const str = address || ''; Ref. https://bobbyhadz.com/blog/javascript-cannot-read-property-split-of-undefined Solve - Cannot read Property 'split' of Undefined in JS | bobbyhadz The "Cannot read property 'split' of undefined" error occurs when trying to call the `split()` method on a variable that stores an `undefined` value... 2022. 5. 24.
Casting between Numbers and String in JavaScript // Number to String var tt = 2 tt += ""; alert(typeof tt); // Result : string // String to Number tt = "2" tt *= 1; alert(typeof tt); // Result : number Ref. https://blog.outsider.ne.kr/361 Javascript에서 String을 Number타입으로 바꾸기 :: Outsider's Dev Story 누가 물어봐서 찾아본 김에 그냥 정리합니다. 아시다시피 Javascript는 명시적인 타입정의가 없습니다. int나 String같이 타입을 명시해서 변수를 정의하지 않고 그냥 var타입으로 정의하면 Javascript가 blog.outsider.ne.kr 2022. 5. 23.
String split in JavaScript const str = 'The quick brown fox jumps over the lazy dog.'; const words = str.split(' '); console.log(words[3]); // expected output: "fox" const chars = str.split(''); console.log(chars[8]); // expected output: "k" const strCopy = str.split(); console.log(strCopy); // expected output: Array ["The quick brown fox jumps over the lazy dog."] Ref. https://developer.mozilla.org/ko/docs/Web/JavaScript.. 2022. 5. 23.
Slicing string in JavaScript const str = 'Mozilla'; console.log(str.substring(1, 3)); // expected output: "oz" console.log(str.substring(2)); // expected output: "zilla" Ref. https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/substring String.prototype.substring() - JavaScript | MDN substring() 메소드는 string 객체의 시작 인덱스로 부터 종료 인덱스 전 까지 문자열의 부분 문자열을 반환합니다. developer.mozilla.org 2022. 5. 20.