登录
原创

JavaScript检测变量数据类型方法

发布于 2021-06-21 阅读 292
  • 前端
  • JavaScript
原创

typeof()

使用typeof(变量)可以检测变量是什么数据类型的

image.png

注意1:

prompt()接收过来的变量是string类型的

image.png
image.png

注意2:

typeof(null)- - -得到结果-object类型

image.png

根据控制台字体颜色,也可以判断数据类型:

数字 - - - - - -蓝色
字符串 - - - - -黑色
boolean类型- - -蓝色
undefined和null- - -灰色
NaN- - - - - - -蓝色

image.png

评论区

零00
7粉丝

时光荏苒,我自清欢

0

0

0

举报