[JavaScript] 소문자, 대문자 변환 toUpperCase(), toLowerCase()

tacowasabii·2024년 6월 23일

JavaScript

목록 보기
9/15
post-thumbnail

자바스크립트에서 문자열의 소문자를 대문자로 변환하거나, 대문자를 소문자로 변환하는 방법은 매우 간단하다. 이를 위해 두 가지 주요 메서드를 사용한다: toUpperCase()toLowerCase().


1. toUpperCase 메서드

toUpperCase 메서드는 문자열의 모든 소문자를 대문자로 변환하는 데 사용된다. 이 메서드는 원본 문자열을 변경하지 않고, 변환된 새로운 문자열을 반환한다. 다음은 toUpperCase 메서드의 사용 예제다.

let lowerCaseString = "hello world";
let upperCaseString = lowerCaseString.toUpperCase();

console.log(upperCaseString); // "HELLO WORLD"

2. toLowerCase 메서드

toLowerCase 메서드는 문자열의 모든 대문자를 소문자로 변환하는 데 사용된다. 이 메서드 역시 원본 문자열을 변경하지 않고, 변환된 새로운 문자열을 반환한다. 다음은 toLowerCase 메서드의 사용 예제다.

let upperCaseString = "HELLO WORLD";
let lowerCaseString = upperCaseString.toLowerCase();

console.log(lowerCaseString); // "hello world"
profile
LG CNS 클라우드 엔지니어 / 웹 프론트엔드 개발자

0개의 댓글