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

用 " typeof " 检测数据类型

一、基本数据类型/简单数据类型

1.number

/**
 * 1.number
 * 十六进制 十进制  科学计数法  小数 分数
 * 检测数据类型  typeof
*/
var a = 10;
var b = 0x11; //0x开头表示十六进制
var c = 011; //0 开头表示八进制
var d = 3e10; //科学计数法
var e = 18 / 5; //分数
console.log(a, b, c, d, e, typeof a, typeof b, typeof c, typeof d, typeof e);//检测结果 number

2.string 字符串类型

/**
 * 2.string类型
 * (字符串类型  "" '' 包裹的就是string类型)
 */
var a = '10';
var b = 'hellojs';
console.log(a, b, typeof a, typeof b);//检测结果 string

3.boolean 布尔类型

/**
 * 3.boolean 布尔类型 true false
 */
var a = true, b = false;
console.log(a, b, typeof a, typeof b);//检测结果 boolean

4.null 空引用类型

/**
 * 5.null 空引用数据类型  检测数据类型的结果 object
 */
var a = null;
console.log(a, typeof a);//检测结果 object

5.undefined 未定义类型

/**
 * 4.undefined 未定义 声明变量不初始化 
 */
var a;//等同于 var a = undefined;
var b = undefined;
console.log(a, b, typeof a, typeof b);//检测结果 undefined

6.Symbol类型

/**
 * 6.symbol 表示一个独一无二的值
 */
var a = Symbol('name');
console.log(a, typeof a);//检测结果 symbol

7.BigInt类型

/**
 * 7.BigInt  表示超出js计算范围以外的数可以使用bigInt处理
 * 当前数字超出最大的数字范围,就会失去精度
 * ===全等 比较数据类型 比较值
 * console.log(9007255619989992===9007255619989993);  true
 */
var a = BigInt(9007255619989992n);
console.log(a, typeof a);  //检测结果 bigint

二、引用数据类型/复杂引用类型

Object对象

/**1.引用数据类型
 * Object对象
 * 检测结果  object
 */
var obj = {
    name: "zhangsan",
    age: 12
};
console.log(obj, typeof obj);

function函数

/**
 * 2.函数 function add(形式参数){}  add(实际参数)
 * typeof function(){} => function
 */
var a = function(a, b) {
    //function add(a,b=>var a,b;)
    console.log(a + b);  // 5
}
//调用函数
a(2, 3);
console.log(a, typeof a);  // [Function: a] function

Array 数组

/**  
 * Array 数组  typeof结果 object
 */
var a = [1, 2, 3, 4, 5];
console.log(a, typeof a);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值