博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
typeof 的复习
阅读量:2120 次
发布时间:2019-04-30

本文共 908 字,大约阅读时间需要 3 分钟。

A问:typeof 是干什么的   B说: 检测数据类型,输出对应的字符串。。。切记是字符串呀!具体如下

"undefined" ------如果某个值为未定义 ; 例如 let a;   typeof a ,     typeof undefined

"boolean"---------如果这个值是布尔值   例如 typeof  true, typeof false

"string"-----如果这个值是字符串  例如: typeof 'true'

"number"----如果这个值是数值  例如: typeof 1

"object"------如果这个值是对象或null   例如: let  a = null; let b = new object(); typeof a   typeof b

"function"------如果这个值是函数 

看起来没啥问题呢 ,但是做题不一定做对,具体来看看呢,请输出下列题目的运行结果

var x = [typeof x, typeof y][1]typeof typeof x;解析:1.首先y未定义所以 x = "undefined"     2.执行 typeofof "undefined" 返回结果是 “string”     3.执行 typeof "string"思考: 多个typeof 连用返回的肯定是 "string" 因为typeof 返回的永远是带引号的类型,再判断肯定是string
(function(){    return typeof arguments})();arguments 是数组, 数组也属于对象类型,所以返回object
var f= function g(){ return '酸菜鱼---又酸又菜又多鱼'}typeof g()  //报错了 g is not defined,因为g()赋值给变量f了typeof f //返回"function"typeof f() //返回"string"
(function (test){    return typeof test.p;}}({test:{ p : 1}})//输出"undefined"

 

 

 

转载地址:http://kaurf.baihongyu.com/

你可能感兴趣的文章
Java工程师成神之路
查看>>
如何在 Linux 上自动设置 JAVA_HOME 环境变量
查看>>
MSSQL复习笔记
查看>>
Spring基础知识汇总
查看>>
Chrome扩展插件
查看>>
log4j.xml 日志文件配置
查看>>
如何删除MySql服务
查看>>
BAT Java和Rti环境变量设置
查看>>
NodeJs npm install 国内镜像
查看>>
python3.5.2 mysql Exccel
查看>>
mysqlDump 导出多表,其中部分表有限制数据内容
查看>>
vi 替换方法
查看>>
BAT 相关
查看>>
ANT集成SVNANT访问SVN(Subversion)
查看>>
高可用架构-- MySQL主从复制的配置
查看>>
jvm调优-从eclipse开始
查看>>
构建微服务:Spring boot 入门篇
查看>>
jvm调优-命令大全(jps jstat jmap jhat jstack jinfo)
查看>>
Spring boot Myibatis
查看>>
spring boot(七):springboot+mybatis多数据源最简解决方案
查看>>