toUpperCase()
메서드는 문자열을 대문자로 변환해 반환합니다.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
구문
str.toUpperCase()
반환 값
대문자로 변환한 새로운 문자열.
예외
TypeError
Function.prototype.call()
등을 사용해null
이나undefined
에서 호출 시.
설명
toUpperCase()
메서드는 문자열을 대문자로 변환한 값을 반환합니다. JavaScript의 문자열은 불변하므로 원본 문자열에는 영향을 주지 않습니다.
예제
기본 사용법
console.log('alphabet'.toUpperCase()); // 'ALPHABET'
문자열이 아닌 this
의 문자열 변환
toUpperCase()
의 this
가 문자열이 아니고, undefined
와 null
도 아니면 자동으로 문자열로 변환합니다.
const a = String.prototype.toUpperCase.call({
toString: function toString() {
return 'abcdef';
}
});
const b = String.prototype.toUpperCase.call(true);
// prints out 'ABCDEF TRUE'.
console.log(a, b);
명세
명세 | 상태 | 비고 |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.0. |
ECMAScript 5.1 (ECMA-262) The definition of 'String.prototype.toUpperCase' in that specification. |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'String.prototype.toUpperCase' in that specification. |
Standard | |
ECMAScript (ECMA-262) The definition of 'String.prototype.toUpperCase' in that specification. |
Living Standard |
브라우저 호환성
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.