javascript 中 typeof 的使用
2016-06-03 08:22
555 查看
javascript 中 typeof 的使用
javascript有五种基本的数据类型(简单数据类型),它们分别是:String、Undefined、Null、Boolean和Number。还有一种复杂数据类型Object。
typeof可以检测给定变量的数据类型。
对一个值使用typeof操作符可能返回下列某个字符串:string、number、boolean、undefined、function和object。
注意:typeof是一个操作符而不是函数,因此圆括号可以省略,而不是必须的。
javascript有五种基本的数据类型(简单数据类型),它们分别是:String、Undefined、Null、Boolean和Number。还有一种复杂数据类型Object。
typeof可以检测给定变量的数据类型。
对一个值使用typeof操作符可能返回下列某个字符串:string、number、boolean、undefined、function和object。
<script type="text/javascript"> function testTypeOf() { var message = "hello"; alert(typeof(message)); //string var num = 110; alert(typeof(num)); //number var boo = false; alert(typeof(boo)); //boolean var unde; alert(typeof(unde)); //undefined var fun = function(){return;}; alert(typeof(fun)); //function var nul = null; alert(typeof(nul)); //object alert(typeof 9); } testTypeOf(); </script>
注意:typeof是一个操作符而不是函数,因此圆括号可以省略,而不是必须的。
相关文章推荐
- JS中判断字符串中出现次数最多的字符及出现的次数
- webpack入门(一)——webpack 介绍
- JSON介绍
- java后端受管bean数据转化为JSON格式传到前端javaScript中
- 文章标题
- 浅谈JavaScript的push(),pop(),concat()方法
- JS Array创建及concat()split()slice()的使用方法
- JS两个数组比较,删除重复值的巧妙方法(推荐)
- 让你一句话理解闭包(简单易懂)
- javascript闭包概念简单解析(推荐)
- JS中判断字符串中出现次数最多的字符及出现的次数的简单实例
- js判断某个字符出现的次数的简单实例
- JavaScript闭包实例详解
- JS判断字符串变量是否含有某个字串的实现方法
- JS使用eval()动态创建变量的方法
- JS中使用变量保存arguments对象的方法
- 深入浅析JavaScript中的arguments对象(强力推荐)
- 浅谈JavaScript 浏览器对象
- JavaScript浏览器对象之一Window对象详解
- 浅谈JavaScript的内置对象和浏览器对象