javascript怎么强制转换成整型


当前第2页 返回上一页

示例

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>数据类型转换</title>

</head>

<body>

<script>

 

    var count=10;

    println(count.toString());

 

    var boolean=true;

    println(boolean.toString());

 

    var today=new Date();

    println(today.toString());

 

    var shoppingCart=['鞋','连衣裙','皮带'];

    println(shoppingCart.toString());

 

 

    var person={};//字面量创建对象

 

    // 设置字面量对象属性

    person.name='huangshiren';

    person.age=58;

    person.appetite=3;

    person.eat=function(){

        document.write('正在吃饭');

    }

 

    println(person.toString());

 

 

    function println(a){

        document.write(a+'<br>');

    }

 

 

</script>

</body>

</html>

转换为布尔类型

Boolean(mix)函数,将任何类型的值转换为布尔值。

示例

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>数据类型转换</title>

</head>

<body>

<script>

 

    var count=10;

 

    println(Boolean(count));

    println(Boolean(0));

    println(Boolean(4<3));

    println(Boolean(null));

    println(Boolean(""));

    println(Boolean(undefined));

 

    var shoppingCart=['鞋','连衣裙','皮带'];

    println(Boolean(shoppingCart));

 

 

 

    var person={};//字面量创建对象

 

    // 设置字面量对象属性

    person.name='huangshiren';

    person.age=58;

    person.appetite=3;

    person.eat=function(){

        document.write('正在吃饭');

    }

 

    println(Boolean(person));

 

    function println(a){

        document.write(a+'<br>');

    }

 

 

</script>

</body>

</html>

更多编程相关知识,请访问:编程视频!!

以上就是javascript怎么强制转换成整型的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

通过代码示例,了解css3+javascript按钮水波纹效果

javascript中new是什么意思

javascript url怎么隐藏

理解并优化javascript代码

javascript 中向上取整、向下取整、四舍五入的操作

javascript如何禁止文字的复制

javascript中的arguments对象的用法介绍

详解javascript里的await/async的作用和用法

javascript中split和join的区别

javascript主要的循环有哪些

更多相关阅读请进入《javascript》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...