w3resource

JavaScript: Check whether a string is lower case or not

JavaScript fundamental (ES6 Syntax): Exercise-197 with Solution

Check String Lowercase

Write a JavaScript program to check whether a string is lower case or not.

  • Convert the given string to lower case, using String.prototype.toLowerCase() and compare it to the original.

Sample Solution:

JavaScript Code:

// Define a function 'isLowerCase' that checks if the given string 'str' contains only lowercase letters
const isLowerCase = str =>
  // Check if the given string 'str' is equal to its lowercase version
  str === str.toLowerCase();

// Test cases to check if the strings contain only lowercase letters
console.log(isLowerCase('abc'));   // true (all letters are lowercase)
console.log(isLowerCase('a3@$'));  // true (all letters are lowercase)
console.log(isLowerCase('Ab4'));   // false (one letter is uppercase)

Output:

true
true
false

Visual Presentation:

JavaScript Fundamental: Check whether a string is lower case or not.
JavaScript Fundamental: Check whether a string is lower case or not.

Flowchart:

flowchart: Check whether a string is lower case or not

Live Demo:

See the Pen javascript-basic-exercise-197-1 by w3resource (@w3resource) on CodePen.


For more Practice: Solve these Related Problems:

  • Write a JavaScript program that returns true if all alphabetic characters in a string are in lowercase.
  • Write a JavaScript function that compares a string to its lowercase version to determine if it is entirely lowercase.
  • Write a JavaScript program that filters out non-letter characters and then checks if the remaining string is lowercase.
  • Write a JavaScript function that returns a boolean after converting the string and comparing with the original.

Go to:


PREV : Check If Null.
NEXT : Check If Function.

Improve this sample solution and post your code through Disqus

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.