Introduction
In this lab, we will explore the concept of checking if a given string is in lowercase or not using JavaScript. We will learn about the String.prototype.toLowerCase() method, which is used to convert a given string to lowercase. By the end of this lab, you will be able to write a function that checks if a string is in lowercase or not.
JavaScript Function to Check if a String is Lowercase
To check if a given string is lowercase, you can use the following JavaScript function. First, convert the string to lowercase using String.prototype.toLowerCase() and then compare it to the original string using strict equality (===).
const isLowerCase = (str) => str === str.toLowerCase();
Here's an example usage:
isLowerCase("abc"); // true
isLowerCase("a3@$"); // true
isLowerCase("Ab4"); // false
To use this function, open the Terminal/SSH and type node.
Summary
Congratulations! You have completed the String Is Lowercase lab. You can practice more labs in LabEx to improve your skills.