What does it mean when there is a number parameter passed to toString?

后端 未结 3 1662
耶瑟儿~
耶瑟儿~ 2020-12-25 12:10

I\'m just wondering what it means to attach a number as a parameter to the toString() method

E.g. obj.toString(10);

I googled a

3条回答
  •  隐瞒了意图╮
    2020-12-25 12:55

    It's not defined as a globally-applicable argument to toString, it only makes sense on Number, where it specifies the base to write in. You can use eg. n.toString(16) to convert to hex.

    The other built-in objects don't use any arguments and JavaScript will silently ignore unused arguments, so passing 16 to any other toString method will make no difference. You can of course make your own toString methods where optional arguments can mean anything you like.

提交回复
热议问题