加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

数据类型

发布时间:2020-12-15 07:55:54 所属栏目:Java 来源:网络整理
导读:1、Number (1) !DOCTYPE htmlhtml head meta charset= " UTF-8 " titleJava Script/title script type= " text/javascript " function test() { var String1 = " nihao " ; alert( typeof String1); } /script /head body bgcolor= " aquamarine " center

1、Number

(1)

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>Java Script</title>
        <script type="text/javascript">
            function test() {
                var String1 = "nihao";
                alert(typeof String1);
            }
        </script>
    </head>

    <body bgcolor="aquamarine">
        <center>
            <button onclick="test()">点击这里</button>
        </center>
    </body>

</html>

(2) 函数的运用:

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>Java Script</title>
        <script type="text/javascript">
            function test() {
                alert(Math.cos(Math.PI));
            }
        </script>
    </head>

    <body bgcolor="aquamarine">
        <center>
            <button onclick="test()">点击这里</button>
        </center>
    </body>

</html>

2、字符串型

(1)类型检测:

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>Java Script</title>
        <script type="text/javascript">
            function test() {
                var String1="nihao";
                alert(typeof String1);
      
            }
        </script>
    </head>

    <body bgcolor="aquamarine">
        <center>
            <button onclick="test()">点击这里</button>
        </center>
    </body>

</html>

(2)与java类似在字符串中“+”具有连接作用:

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>Java Script</title>
        <script type="text/javascript">
            function test() {
                var String1="nihao"+"Tom";
                alert(String1);
      
            }
        </script>
    </head>

    <body bgcolor="aquamarine">
        <center>
            <button onclick="test()">点击这里</button>
        </center>
    </body>

</html>

(3)基本函数的使用:

length属性:

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>Java Script</title>
        <script type="text/javascript">
            function test() {
                var String1="nihao";
                alert(String1.length);
      
            }
        </script>
    </head>

    <body bgcolor="aquamarine">
        <center>
            <button onclick="test()">点击这里</button>
        </center>
    </body>

</html>

获取字符串中的某个字符:

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>Java Script</title>
        <script type="text/javascript">
            function test() {
                var String1="nihao";
                alert(String1.charAt(1));
      
            }
        </script>
    </head>

    <body bgcolor="aquamarine">
        <center>
            <button onclick="test()">点击这里</button>
        </center>
    </body>

</html>

3、布尔型

类型测试:

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>Java Script</title>
        <script type="text/javascript">
            function test() {
                var String1=true;
                alert(typeof String1);
      
            }
        </script>
    </head>

    <body bgcolor="aquamarine">
        <center>
            <button onclick="test()">点击这里</button>
        </center>
    </body>

</html>

4、Object类型

5、undefined类型

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>Java Script</title>
        <script type="text/javascript">
            function test() {
                var String1;
                alert(typeof String1);
      
            }
        </script>
    </head>

    <body bgcolor="aquamarine">
        <center>
            <button onclick="test()">点击这里</button>
        </center>
    </body>

</html>

?

即定义了但未赋值。

(6)null类型

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>Java Script</title>
        <script type="text/javascript">
            function test() {
    num=null;
                alert(typeof(num));
      
            }
        </script>
    </head>

    <body bgcolor="aquamarine">
        <center>
            <button onclick="test()">点击这里</button>
        </center>
    </body>

</html>

访问的对象不存在(未声明)。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读