JavaScript typeof

JavaScript typeof, null, undefined, valueOf().


##typeof operator

You can use the typeof operator to detect the data type of a variable.

Example

    PHP中文网(php.cn) 

typeof 操作符返回变量或表达式的类型。

Tips: In JavaScript, an array is a special object type. So typeof [1,2,3,4] returns object.


Null

In JavaScript, null means "nothing".

null is a special type with only one value. Represents an empty object reference.

Use typeof to detect null and return object.

You can set it to null to clear the object:

Instance

    PHP中文网(php.cn) 

对象可以通过设置为 null 来清空。

Run the program to try it


You can set it to undefined to clear the object:


Instance

    PHP中文网(php.cn) 

对象可以设置为 undefined 来清空。

Run the program and try it


Undefined

In JavaScript, undefined is a variable that has no set value.

typeof A variable with no value will return undefined.

Example

    PHP中文网(php.cn) 

变量的值如果不存在则该变量值为 undefined

Run the program to try it


Any variable can be cleared by setting the value to undefined. The type is undefined.

Instance

    PHP中文网(php.cn) 

变量可以通过设置 undefined 来清空。

Run the program and try it


Undefined The difference with Null

    PHP中文网(php.cn) 

Run the program and try it



Continuing Learning
||
菜鸟教程(runoob.com)

typeof 操作符返回变量或表达式的类型。

submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!