[JS] 대문자랑 소문자 어떻게 확인해요?

전윤선·2022년 12월 7일
0
post-thumbnail

대문자로 변환하는 방법

toUpperCase() 메서드를 통해 문자열을 대문자로 변환할 수 있다.

const str = "Good Morning, Yoonsun";
const upperCaseStr = str.toUpperCase();
console.log(upperCaseStr) // GOOD MORNING, YOONSUN

소문자로 변환하는 방법

toLowerCase() 메서드를 활용하자!

const str = "Good Morning, Yoonsun";
const lowerCaseStr = str.toLowerCase();
console.log(lowerCaseStr) // good morning, yoonsun

대문자/소문자 확인하는 방법

const str = "Good Morning, Yoonsun";
const upperCaseStr = str.toUpperCase();
const lowerCaseStr = str.toLowerCase();

// 대문자인지 확인
if (str === upperCaseStr) {
  console.log("대문자다!");
}

// 소문자인지 확인
if (str === lowerCaseStr) {
  console.log("소문자다!");
}
profile
아무것도 몰라효 (ノ◕ヮ◕)ノ*:・゚✧

0개의 댓글