[Javascript]-기본 기능 익히기

오다경·2022년 11월 10일
0

javascript basic

목록 보기
1/12

- 자바스크립트 내 문자의 길이 세는 방법

매개변수에 .length를 사용하여 값을 구할 수 있다.

/**
 * @param {string} str
 */

function getCharCount(str) {
	return str.length
}

console.log(getCharCount("Sam")); // 3
console.log(getCharCount("Alex 123")); // 8
console.log(getCharCount("Charley is here")); // 15

- 자바스크립트 내 대소문자 변환 방법

대소문자로 변환할 때 사용하는 함수는 toUpperCase() 와 toLowerCase() 함수이다
eg) 소문자 변환 활용 방법

/**
 *param {string} name
 */

function lowerName(name) {
    return name.toLowerCase()
}
console.log(lowerName("Sam")); // "sam"
console.log(lowerName("ALEX")); // "alex" 입력하세요
profile
개발자 꿈나무🌳

0개의 댓글