js数据类型总结以及typeof详情

js数据类型总结

一个正在努力爱好运动的程序猿-
座右铭:越努力越幸运,越运动越健康,热爱编程,热爱运动。



一、基本类型

基本类型: number string undefined null boolean 属于栈类型 存值

typeof(1) === "number"
typeof('1')=== "string"
typeof(a) === "undefined"
typeof(null) ==="object"
typeof(true) === "boolean"
/*
*typeof 返回的数据类型6种
      (1)number;
      (2)string;
      (3)boolean;
      (4)object;
      (5)function;
      (6)undefined;
*/

二、引用类型

引用类型: array object function 属于堆类型 存地址

代码如下(示例):

/*
*主要讲typeof的各种返回值
*typeof:操作符返回一个字符串,表示未经计算的操作数的类型。
*typeof语法:typeof或者typeof()      有无括号都可以
*/
//1.number
typeof(37) === "number";
typeof(3.14) === "number";
//Math.LN2 属性表示 2 的自然对数,约为 0.693: ==Ln(2)
typeof(Math.LN2) === "number";
typeof(Infinity) === "number";
typeof(NaN) === "number";
typeof(Number(1)) === "number"; //不要使用这种形式

//2.string
typeof("") === "string";
typeof("a") === "string";
typeof(typeof 1) === "string";
typeof(String("abc")) === "string"; //不要使用这种形式

//3.boolean
typeof(true) === "boolean";
typeof(false) === "boolean";
typeof(Boolean(true)) === "boolean"; //不要使用这种形式

//4.underfined
typeof(未赋值的变量) ==="underfined"

//5.object
typeof({}) ==="object"
typeof([]) ==="object"
//区分数组和对象使用 Array.isArray  或者 Object.prototype.toString.call
typeof(new Date())==="object"
//让人产生迷惑的
typeof new Boolean(true)==="object";
typeof new Number(1)==="object";
typeof new String("1")==="object";

//6.function
typeof(function(){}) === "function"
typeof(class x{}) === "function"
typeof(Math.sin) === "function"
typeof(new Function) === "function"

总结

原文详细看这里----------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值