Code has been added to clipboard!

toUpperCase

Reading time 2 min
Published Sep 8, 2017
Updated Oct 2, 2019

JavaScript upperCase: Main Tips

  • This method is used to convert all letters in a specified string to JavaScript uppercase.
  • The toUpperCase() method does not affect the original string, returning a new modified string instead.

Function Explained

Once you apply JavaScript toUpperCase() method to a string, all of the lower case letters will be capitalized. Therefore, JavaScript upperCase method is perfectly-suited for quickly converting all letters in a specified string in JavaScript uppercase.

However, there are some additional factors you have to bear in mind. For instance, the toUpperCase JavaScript method will not modify numbers, special characters and will retain the originally-capitalized letters.

Furthermore, the original string you want to change with the JavaScript toUpperCase() function won't be modified. Instead, the method generates a new string with all letters properly capitalized.

This example illustrates how you can easily capitalize letters with the toUpperCase JavaScript method:

Example
var str = "Hi, Mark!";
var res = str.toUpperCase();

By using the JavaScript upperCase function, we can also implement the JavaScript capitalize first letter task. In cases when you only want to have the first letter capitalized, you should apply uppercaseFirstLetter to strings.

Tip: toLowerCase() method can be used for converting the string to lowercase letters.

Learn Standard Syntax

As you can see from the example below, the rules for writing JavaScript toUpperCase function do not require to remember many things. The most prominent feature is the capitalization of the method which you should attempt to keep in your code:

string.toUpperCase()

You should notice that parentheses are empty, meaning that it does not take any arguments.

Return Value

The JavaScript upperCase method will return an obvious value: a newly-generated string. All of the letters in the string will be capitalized, while the original string remains the same.

Return Value: A string, which represents the original string with the letters all converted to uppercase.
JavaScript Version: ECMAScript 1
What Is JavaScript Used For?
Tutorial
Introduction
Output
Syntax
Comment
Commands
Operators
Comparison and Logical Operators
Data Types
Math.random()
Type Conversion
Function Definitions
Events
Objects
Object Properties
Prototype
Array
Sorting Arrays
Strings
Numbers
Number Format
Math Object
Onclick Event
Date
Date Formats
Scope
Regular Expressions
Reserved Words
Common Mistakes
Performance
Forms
Form Validation
Window: The Browser Object Model
Popup Boxes
Cookies
JSON
AJAX Introduction
AJAX Form
Automatic File Download
Functions
Array Methods
String Methods
Date Methods
Timing Events
Cheat Sheet
JavaScript in HTML
HTML DOM Methods
HTML DOM Changing HTML
HTML DOM Animation
HTML DOM EventListener
HTML DOM Navigation
HTML DOM NodeList
HTML DOM Element Nodes
Array Functions
Boolean
Calling a Function
Date Functions
Global Objects
Input Text
Operator
Statements
String Functions
Math
Math.random
Number
RegEx
alert
array.filter
array.length
array.map
array.reduce
array.push
array.sort
break and continue
className
confirm
decodeURIComponent
for
forEach
if
indexOf
innerHTML
location.reload
number.toString
onclick
onload
parseInt
prompt
replace
setAttribute
setInterval
setTimeout
slice
splice
string.includes
string.indexOf
string.split
style.display
submit
substr
substring
switch
test
throw, try and catch
toLowerCase
toUpperCase
use strict
while
window.history
window.location
window.navigator
window.screen