JS数据类型转换

  上一篇文章写到JavaScript的数据类型,总共有7种。

  今天来研究研究这7种数据类型的转换。

  一,各种类型转换为number类型

         方法:①Number(‘1’)

                              image

                             ②parseInt(‘1’,10)

                             image

                            ③parseFloat(‘1.33’)

                             image

                           ④’1’-0

                             image

                           ⑤+’1’

                            image

二、各种类型转换为string类型

        方法:①(数据类型)+’’

                   image

                   ②window.String();

                   image

三、各种类型转换为布尔值

       方法:①Boolean()

                  image

                 ②!!

                 image

       有两种特殊情况:Boolean(‘’);///true
                                  Boolean({});///false

四、五个falsy值

       Number:(0,NaN)

       String:(’’)

       null

       undefined


posted @ 2018-07-18 22:38  lxxxxxxxx  阅读(107)  评论(0)    收藏  举报