typeof类型 js中typeof的用法
JS中的变量是松散类型(即弱类型)的,可以用来保存任何类型的数据。
字符串 | 描述 |
undefined | 未定义 |
boolean | 布尔值 |
string | 字符串 |
number | 数值 |
object | 对象或者null |
function | 函数 |
2,undefined类型
undefined只是一个值。当我们声明一个变量,没有做初化的时候。我们调用这个变量就会返回一个值undefined。如:
var name; alert(name);如果我们把alert语句写成alert(people);同样是返回undefined。这两种情况分别是一、只是定义了变量没有做相应的
初始化。二、没有声明相应的变量。调用报错。ps:在声明变量的时候最好进行初始化。
3,null类型。
null是一个只有一个值的特殊类型。表示一个空对象引用。用typeof检测返回是object。
undefined是派生自null。undefined==null。
4,Boolead类型。
Boolean 类型有两个值(字面量): true 和 false。 而 true 不一定等于 1, false 不一定等于 0。 JavaScript 是区分大小写的,True 和 False 或者其他都不是 Boolean 类型的值。boolean可以与其他类型转化。
以下是其他类型转换成 Boolean 类型规则:
数据类型 | 转换为 true 的值 | 转换为 false 的值 |
Boolean | true | false |
String | 任何非空字符串 | 空字符串 |
Number | 任何非零数字值(包括无穷大) | 0 和 NaN |
Object | 任何对象 | null |
Undefined | undefined |
5.Number 类型
Number 类型包含两种数值:整型和浮点型。
通过 Number.POSITIVE_INFINITY 和 Number.NEGATIVE_INFINITY 得到 Infinity(正无穷)及-Infinity(负无穷)的值。 alert(Number.POSITIVE_INFINITY); //Infinity(正无穷) alert(Number.NEGATIVE_INFINITY);//-Infinity(负无穷)
var box = 12 / 0; //Infinity
6.String 类型
String 类型用于表示由于零或多个 16 位 Unicode 字符组成的字符序列,即字符串。字 符串可以由双引号(")或单引号(')表示。
- <script>
- document.write ("typeof(1): "+typeof(1)+"<br>");
- document.write ("typeof(NaN): "+typeof(NaN)+"<br>");
- document.write ("typeof(Number.MIN_VALUE): "+typeof(Number.MIN_VALUE)+"<br>")
- document.write ("typeof(Infinity): "+typeof(Infinity)+"<br>")
- document.write ("typeof(\"123\"): "+typeof("123")+"<br>")
- document.write ("typeof(true): "+typeof(true)+"<br>")
- document.write ("typeof(window): "+typeof(window)+"<br>")
- document.write ("typeof(document): "+typeof(document)+"<br>")
- document.write ("typeof(null): "+typeof(null)+"<br>")
- document.write ("typeof(eval): "+typeof(eval)+"<br>")
- document.write ("typeof(Date): "+typeof(Date)+"<br>")
- document.write ("typeof(sss): "+typeof(sss)+"<br>")
- document.write ("typeof(undefined): "+typeof(undefined)+"<br>")
- </script>
Math.floor是什么?JavaScript floor() 方法
Javascript 中的false、0、null、undefined和空字符串对象
js中return;、return true、return false;区别
jquery number() parseInt() parseFloat()
js字符串函数|JS截取字符串函数
原文地址:http://www.35ui.cn/post/20160204391.html 标签:jsjavascriptjs手册typeof
上一条: url传中文参数乱码 url参数乱码
下一条: 黄色网站 最黄色网站网址在这里