Author -  Sai gowtham

How to solve toLowerCase is not a function in JavaScript

In this tutorial, we are going to learn about how to solve the TypeError: toLowerCase is not a function in JavaScript

When we use a ‘toLowerCase()’ method on a value which is not a data type string we will get the following error in our console.

Example:

const value = 8999;

console.log(value.toLowerCase());

Output:

"TypeError: value.toLowerCase is not a function

In the example above, we are getting the error because we are using the ‘toLowerCase()’ method on a datetype number, but the toLowerCase() is not available on the number datatype.

To solve the “TypeError: toLowerCase is not a function”, make sure to call the toLowerCase() method on a data type string or convert the number to string before calling the toLowerCase() method on it.

Here is an example:

const value = 8999;

const result = value.toString().toLowerCase();
console.log(result);

Output:

8999

In the example above, we first converted the given value to a string using the toString() method, then we called a toLowerCase() method on it.

Note: The ‘toLowerCase()’ method creates a new string with the values that passes the test condition.

Type checking

To avoid the run time errors, we can also check the given datatype is a string or not before calling the toLowerCase() method on it.

Here is an example:

const value = 8999;

if(typeof value === 'string'){
    console.log(value.toLowerCase());
}else{
    console.log('Given value is not a string');
}

Conclusion

The “toLowerCase is not a function” error occurs, when we call a toLowerCase() method on a value which is not a string. To solve the error, convert the value to an string before calling the toLowerCase() method on it or make sure to use the toLowerCase() method on a valid strings.

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY