What is string.toUpperCase() in TypeScript?

Overview

TypeScript enables us to get the uppercase representation of a string. But the string.toUpperCase() method does not permanently modify the string. It only returns the string as uppercase.

Syntax

string.toUpperCase()
Syntax for toUpperCase() method in TypeScript

Parameter

string: This is the string we want to convert to uppercase.

Return value

This method returns the uppercase equivalent of the string string .

Code example

Let's look at the code below:

export {}
// create some strings.
let name:string = "Theodore"
let role:string = "Software Developer"
let nickName:string = "Kcee"
let hubby:string = "Coding"
// convert to uppercase
console.log(name.toUpperCase())
console.log(role.toUpperCase())
console.log(nickName.toUpperCase())
console.log(hubby.toUpperCase())

Code explanation

  • Line 1: We export our file as a module.
  • Lines 4 to 7: We create some strings.
  • Lines 10 to 13: We use the toUpperCase() method to get the uppercase versions of our strings and print them to the console.

Free Resources