pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase

tps://developer.mozilla.org/favicon.ico" />

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

String.prototype.toUpperCase()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.

StringtoUpperCase() 方法将该字符串转换为大写形式。

尝试一下

const sentence = "The quick brown fox jumps over the lazy dog.";

console.log(sentence.toUpperCase());
// Expected output: "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG."

语法

js
toUpperCase()

返回值

一个新的字符串,表示转换为大写的调用字符串。

描述

toUpperCase() 方法返回将字符串转换为大写形式后的值。由于 JavaScript 中的字符串是不可变的,因此此方法不会影响字符串本身的值。

示例

基本用法

js
console.log("alphabet".toUpperCase()); // 'ALPHABET'

将非字符串类型的 this (上下文)转为字符串

此方法会将任何非字符串类型的值转为字符串,当你将其上下文 this 值设置为非字符串类型

js
const a = String.prototype.toUpperCase.call({
  toString: function toString() {
    return "abcdef";
  },
});

const b = String.prototype.toUpperCase.call(true);

// 输出 'ABCDEF TRUE'。
console.log(a, b);

规范

Specification
ECMAScript® 2026 Language Specification
# sec-string.prototype.touppercase

浏览器兼容性

参见

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy