欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js中typeOf用法

程序员文章站 2024-01-28 14:25:16
...

JS中的变量是松散类型(即弱类型)的,可以用来保存任何类型的数据。

typeof 可以用来检测给定变量的数据类型,可能的返回值:1. 'undefined' --- 这个值未定义;

2. 'boolean'    --- 这个值是布尔值;

3. 'string'        --- 这个值是字符串;

4. 'number'     --- 这个值是数值;

5. 'object'       --- 这个值是对象或null;

6. 'function'    --- 这个值是函数。

 

Js代码 js中typeOf用法
            
    
    博客分类: js js中typeOf用法
            
    
    博客分类: js

           var aa = 'test string';   

           alert(typeof aa);  // 'string'   

           alert(typeof 90);  // 'number'