.toLowerCase not working, replacement function?

后端 未结 5 609
感动是毒
感动是毒 2020-12-29 01:14

The .toLowerCase method is giving me an error when I try to use it on numbers. This is what I have:

var ans = 334;
var temp = ans.toLowerCase();         


        
5条回答
  •  独厮守ぢ
    2020-12-29 01:21

    It's not an error. Javascript will gladly convert a number to a string when a string is expected (for example parseInt(42)), but in this case there is nothing that expect the number to be a string.

    Here's a makeLowerCase function. :)

    function makeLowerCase(value) {
      return value.toString().toLowerCase();
    }
    

提交回复
热议问题