Nerd For Tech
Published in

Nerd For Tech

Basics of Javascript · String · toUpperCase() (method)

This article is a transcript of my free youtube series about basics of web development. If you prefer watching over reading, feel free to visit my channel “Dev Newbs”.

Hello there Dev Newbs! Method for the day will again feel like a one that we already covered. That’s because we already did cover its “locale” version. It is now time to take the other sibling for a spin, too. Let’s get it done.

toUpperCase() method converts a string to uppercase letters. The method does not change the original string.

Again, this method does not have any input parameters at all.

Return value of the method is a string, representing the value of an original string converted to uppercase.

Let’s have a look at some of the examples for basic usage in example 1.

const cities = "new york, paris, milan, tokyo, ...";// use the method with variable containing string value
cities.toUpperCase()
// OUTPUT: NEW YORK, PARIS, MILAN, TOKYO, ...// use it directly with a string value
"alphabet".toUpperCase()
// OUTPUT: ALPHABET// no lowercase - original value equals to converted value
let originalString = "HELLO THERE!";
let convertedString = originalString.toUpperCase();
originalString === convertedString// OUTPUT: true// can't call with null / undefined
try{
console.log(null.toUpperCase());
}
catch(error){
console.log(error);
}
// OUTPUT:
// TypeError: Cannot read property 'toUpperCase' of null
try{
console.log(undefined.toUpperCase());
}
catch(error){
console.log(error);
}
// OUTPUT:
// TypeError: Cannot read property 'toUpperCase' of undefined

We can easily convert lowercase characters to uppercase just like in use case 1 and 2.

If we have a string with no lowercase letters, the original string and converted string are equal.

However, there are few cases where this method will throw TypeError. One of those is when we try to call the method with “null” or “undefined”. But other than that, we are golden.

So that was one of the good and simple String methods called toUppercase(). As always, thank you for your time and your attention. And I’ll see you again soon with the next method.

--

--

--

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Recommended from Medium

Create a Shopping List with Akita and Angular

Reserved Keyword In Javascript?

Reserved Keyword In Javascript?

Easily 4 Steps: Auto Deploy Vue.js App on Heroku

Angular routing

My Notes on npm and Yarn. You’re Welcome!

10 Interview Questions Every JavaScript Developer Should Know

Day 12: Lifecycle methods in React continue

Setting up a Shopify app with Rails 5.1, Webpack, React, and Polaris

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jakub Korch

Jakub Korch

Web enthusiast, programmer, husband and a father. Wannabe entrepreneur. You name it.

More from Medium

3 ways to split and remove HTML from a string

Have you heard of Application Frameworks…?

Wrapper in JavaScript to avoid writing Try/Catch multiple times

How to import ESLint issues into SonarQube overview analysis in a frontend application