- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Let’s understand the syntax of the ‘z’[‘toUpperCase’]() below.
let result = 'z'['toUpperCase'](); // returns 'Z', string in upper case
The above syntax is same as the below.
let string = 'z'; let result = string.toUpperCase();
Why does ‘z’[‘toUpperCase’]() work?
Before we move ahead with this tutorial, let’s understand the 2 ways to access the properties of any class using its object.
The first way to access the properties of any class using its object is the dot operator, and users can see the syntax below for that.
let obj = new object(); obj.method(); obj.variable;
Now, users can see the second way to access the class properties using its object.
let obj = new object(); obj[method](); obj[variable];
In the ‘z’[‘toUpperCase’], we have used the second method to access the string class method. Here, ‘z’ is the string, but when we use it with the second syntax, it converts to the object. ‘toUpperCase’ is the method of the String class, and ‘()’ represents the accessed property is the method, and invoke it by taking the object as a reference.
Let’s understand the above format to call the toUpperCase() method using the example below.
In the example below, we have access to the toUpperCase() method of the String class and apply it to the string object. We have used the different string objects and converted them into the upper case in the example below. Users can see the output for the different values.
In this tutorial, we have learned how does ‘z’[‘toUpperCase’]() syntax will work. It works as same as string.toUpperCase() method. In the same way, users can access the other class properties, such as variables and methods.
- How does $('iframe').ready() method work in jQuery?
- How does parameters 'c' and 'cmap' behave in a Matplotlib scatter plot?
- How does the 'in' operator work on a tuple in Python?
- Update 'a' record with 'b' and 'b' with 'a' in a MySQL column (swap) with only 'a' and 'b' values?
- What is difference between '.' , '?' and '*' in Python regular expression?
- The difference between 'AND' and '&&' in MySQL?
- How to Use 'U' and 'L' formatters in Arduino?
- MySQL where column = 'x, y, z'?