Type conversion of Boolean to Number in JavaScript

前端 未结 3 1013
春和景丽
春和景丽 2021-01-27 09:22

I was working on type conversion of Boolean values to Number in javascript.

console.log(new Number(true));//Prints 1
console.log(+true);//Prints 1
console.log(pa         


        
3条回答
  •  耶瑟儿~
    2021-01-27 09:58

    Because parseInt expects a string and 'true' is NaN.

    From MDN:

    parseInt()

    The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).

提交回复
热议问题