touppercase()
时间: 2023-11-13 12:03:04 浏览: 41
The touppercase() method is a built-in function in JavaScript that returns a new string with all the characters in uppercase. It does not modify the original string.
Syntax:
```
string.toUpperCase()
```
Example:
```
let str = "hello world";
let upperStr = str.toUpperCase();
console.log(upperStr); // "HELLO WORLD"
console.log(str); // "hello world"
```
In the above example, the touppercase() method is called on the string "hello world" which returns a new string with all the characters in uppercase. The original string remains unchanged. The upperStr variable now holds the new uppercase string.
相关问题
touppercase用法
`toUpperCase()` 是 JavaScript 中的字符串方法,它将字符串中的所有字母转换为大写字母并返回一个新字符串。例如:
```javascript
const str = "hello world";
const strUpperCase = str.toUpperCase();
console.log(strUpperCase); // 输出 "HELLO WORLD"
```
可以看到,原始字符串 `str` 中的所有字母都被转换为大写字母,并存储在新字符串 `strUpperCase` 中。需要注意的是,`toUpperCase()` 方法不会修改原始字符串,而是返回一个新字符串。此外,该方法只会将字母转为大写,其他字符(如数字、符号等)不会受到影响。
js toUpperCase
"toUpperCase" 是 JavaScript 中的一个字符串方法,用于将字符串中的所有字母转换为大写。例如,如果你有一个字符串变量 "hello",你可以使用 "toUpperCase" 方法将它转换为 "HELLO"。以下是一个示例:
```
let str = "hello";
let upperCaseStr = str.toUpperCase();
console.log(upperCaseStr); // 输出 "HELLO"
```
请注意,"toUpperCase" 方法只能将字符串中的字母字符转换为大写,而不会影响其他字符(如数字或标点符号)。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)