首页 > 技术文章 > typeof运算符

zhaoxinmei-123 2018-04-22 15:13 原文

语法:运算符后跟操作数

typeof operand    typeof (operand)  注:括号是可选的

参数

operand:是一个表达式,对象或原始值,其类型将被返回

返回值:typeof可能的返回值

示例:

当函数无明确返回值时,返回的也是undefind:

function testfunc(){}

typeof testfunc() ==='undefined'

对于未声明的变量也返回undefined:

var str1;

typeof str1 ==='undefined'

typeof str2==='undefined'

语法中需要括号:圆括号,以确定表达式的数据类型

 

推荐阅读