js基本数据类型以及检测方式与返回对象

救无数的人 3个月前 已收到2个回答 举报

无力挽回 2星

共回答了231个问题采纳率:94.6% 评论

基本数据类型有:数字(number),字符串(string),布尔(boolean),NULL和undefined

检测方法使用js的typeof类型进行数据类型判断,返回的对象分别是:

1:数字的返回类型是Number,判断条件是为:typeof 需要判断的数字 == Number,则表示这个数是一个数字类型;

2:字符串的返回类型是String,注意这里所有返回的值是一个字符串,并且首字母大写;

3:布尔返回的类型是Boolean,表示数据的真假

4:Null的返回类型是Object,所以这里判断null对象则不能使用typeof进行判断,需要用instance of条件进行判断

5:undefined返回类型是undefined,表示变量未定义。

1小时前

27

思韵枫 2星

共回答了230个问题 评论

对象为object 了解js的都知道, 有个typeof 用来判断各种数据类型,有两种写法:typeof xxx ,typeof(xxx) 如下实例:

typeof 2 输出 number typeof null 输出 object typeof {} 输出 object typeof [] 输出 object typeof (function(){}) 输出 function typeof undefined 输出 undefined typeof '222' 输出 string typeof true 输出 boolean 这里面包含了js里面的五种数据类型 number string boolean undefined object和函数类型 function

21小时前

30
可能相似的问题

猜你喜欢的问题

热门问题推荐

Copyright © 2024 微短问答 All rights reserved. 粤ICP备2021119249号 站务邮箱 service@wdace.com