String Is Uppercase

JavaScriptJavaScriptBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In this lab, we will explore how to check if a given string is in uppercase using JavaScript. We will create a function that converts the string to uppercase using the String.prototype.toUpperCase() method, and then compare it to the original string. By the end of this lab, you will have a better understanding of string manipulation in JavaScript and how to check for uppercase strings.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL javascript(("`JavaScript`")) -.-> javascript/BasicConceptsGroup(["`Basic Concepts`"]) javascript(("`JavaScript`")) -.-> javascript/ToolsandEnvironmentGroup(["`Tools and Environment`"]) javascript/BasicConceptsGroup -.-> javascript/variables("`Variables`") javascript/BasicConceptsGroup -.-> javascript/data_types("`Data Types`") javascript/BasicConceptsGroup -.-> javascript/arith_ops("`Arithmetic Operators`") javascript/BasicConceptsGroup -.-> javascript/comp_ops("`Comparison Operators`") javascript/ToolsandEnvironmentGroup -.-> javascript/debugging("`Debugging`") subgraph Lab Skills javascript/variables -.-> lab-28448{{"`String Is Uppercase`"}} javascript/data_types -.-> lab-28448{{"`String Is Uppercase`"}} javascript/arith_ops -.-> lab-28448{{"`String Is Uppercase`"}} javascript/comp_ops -.-> lab-28448{{"`String Is Uppercase`"}} javascript/debugging -.-> lab-28448{{"`String Is Uppercase`"}} end

Function to Check if a String is Uppercase

To check if a string is in uppercase, follow these steps:

  1. Open the Terminal/SSH.
  2. Type node.
  3. Use the function isUpperCase() to convert the given string to uppercase, using String.prototype.toUpperCase(), and compare it to the original string.
  4. The function will return true if the string is in uppercase and false if it is not.

Here is an example code:

const isUpperCase = (str) => str === str.toUpperCase();

console.log(isUpperCase("ABC")); // true
console.log(isUpperCase("A3@$")); // true
console.log(isUpperCase("aB4")); // false

Summary

Congratulations! You have completed the String Is Uppercase lab. You can practice more labs in LabEx to improve your skills.

Other JavaScript Tutorials you may like