且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

js数据类型和typeof

更新时间:2022-08-13 07:39:11

一、6种数据类型(一说7种)

<meta charset="utf-8" />

<script type="text/javascript">
    // 数据类型  数字、字符串、布尔、对象、null、undefined、数组
    // 数字
    var num = 2;
    var num2 = 2.30;
    show(typeof num);
    
    // 字符串
    var str = 'abc';
    var str2 = "123";
    show(typeof str);
    
    // 布尔
    var boo1 = true;
    var boo2 = false;
    show(typeof boo1);
    
    // 对象
    var obj = {
        name: '张三',
        age: 18
    }
    show(typeof obj);
    
    // null
    var aa = null;
    show(typeof aa);
    
    // undefined
    var bb;
    show(typeof bb);
    
    // 数组
    var arr = ['a', 2, null];
    show(typeof arr);
    
    
    
    function show(data) {
        document.write(data);
        document.write('<br />');
    }
    
</script>

基本数据类型和引用数据类型

  1. 基本数据类型
  2. 引用数据类型