var a1;

var a2 = true;
var a3 = 1;
var a4 = "Hello";
var a5 = new Object();
var a6 = null;
var a7 = NaN;
var a8 = undefined;

alert(typeof a); //显示"undefined"
alert(typeof a1); //显示"undefined"
alert(typeof a2); //显示"boolean"
alert(typeof a3); //显示"number"
alert(typeof a4); //显示"string"
alert(typeof a5); //显示"object"
alert(typeof a6); //显示"object"
alert(typeof a7); //显示"number"
alert(typeof a8); //显示"undefined"

从上面的代码 可以看出 null  是 特殊的object 类型,NaN 是特殊的number类型。

未定义的对象是undefined类型。定义了对象但是没赋值的对象也是undefined类型。

var a1;        //a1的值为undefined
var a2 = null;
var a3 = NaN;

alert(a1 == a2); //显示"true"
alert(a1 != a2); //显示"false"

alert(a1 == a3); //显示"false"
alert(a1 != a3); //显示"true"

alert(a2 == a3); //显示"false"
alert(a2 != a3); //显示"true"

alert(a3 == a3); //显示"false"
alert(a3 != a3); //显示"true"

从上面的代码可以得出结论:(1)undefined与null是相等;(2)NaN与任何值都不相等,与自己也不相等。

在JavaScript中,null与undefined一度使人迷惑。下面的分析,有利于你更清晰的认知它(或者让你更迷惑): 

- null是关键字;undefined是Global对象的一个属性 

- null是对象(空对象, 没有任何属性和方法);undefined是undefined类型的值。试试下面的代码: 

       document.writeln(typeof null); //return object 
       document.writeln(typeof undefined); //return undefined - 对象模型中,所有的对象都是Object或其子类的实例,但null对象例外:
       document.writeln(null instanceof Object); //return false - null“等值(==)”于undefined,但不“全等值(===)”于undefined:
       document.writeln(null == undefined); //return true
       document.writeln(null === undefined); //return false - 运算时null与undefined都可以被类型转换为false,但不等值于false:
       document.writeln(!null, !undefined); //return true,true
       document.writeln(null==false); //return false
       document.writeln(undefined==false); //return false

Javascript中类型: undefined, number ,string ,object ,boolean的更多相关文章

  1. Javascript中类型的判断

    数据类型的判断有这么几种方式 1.一元运算符 typeOf 2.关系运算符 instanceof 3.constructor 属性 4.prototype属性 一.typeof typeof的返回值有 ...

  2. JavaScript 中的undefined and null 学习

    JavaScript 中的undefined and null learn record from the definitive guide to html5 JavaScript 中有两个特殊值:u ...

  3. JavaScript中 null 的 typeof是object

    JavaScript中  null 的 typeof是object

  4. javascript中常见undefined与defined的区别

    在JavaScript中相信“undefined”与“defined”对大家来说都肯定不陌生,但是又不是很清楚它们的区别,先看两个demo我们再说, 例1. console.log(parms); / ...

  5. JavaScript中的Undefined / Null 类型相关说明

    1,综述: ※Undefined 和 Null是JavaScript中的两种数据类型(其他的类型还有:Boolean, String, Number, Object). ※Undefined类型只有一 ...

  6. javascript中的undefined,null,"",0和false的云集

    在各种各样的数据类型中,我们都会为其定义一个"空值"或"假值",比如对象类型的空值null,.NET Framework中数据库字段的空值DBNull,bool ...

  7. JavaScript 基本类型值-Undefined、Null、Boolean

    ▓▓▓▓▓▓ 大致介绍 ECMAScript中有5中简单的数据类型(也称为基本数据类型):Undefined.Null.Boolean.Number.String. ▓▓▓▓▓▓ Undefined ...

  8. Javascript中的undefined、null、""、0值和false的区别总结

    在程序语言中定义的各种各样的数据类型中,我们都会为其定义一个"空值"或"假值",比如对象类型的空值null,.NET Framework中数据库字段的空值DBN ...

  9. JavaScript 中的对象深度复制(Object Deep Clone)

    JavaScript中并没有直接提供对象复制(Object Clone)的方法. JavaScript中的赋值,其实并不是复制对象,而是类似`c/c++`中的引用(或指针),因此下面的代码中改变对象b ...

随机推荐

  1. mysql 8 安装及更改密码

    一 下载ZIP版的安装文件, 二 解压缩至指定的目录,如:d:\mysql8.0 三 在所在目录下,新建mysql.ini文件 [mysql] # 设置mysql客户端默认字符集 default-ch ...

  2. HP proliant服务器从usb启动

    1,开机出现自检画面开始按F9进入设置,进入BIOS 选择standard boot order(rpl),把usb driver放在第一位,保存好 2,按F1开始启动. (注:我使用ubuntu14 ...

  3. sql server生成不重复的时间字符串

    ),REPLACE(CONVERT(,),GETDATE()),'.',''))

  4. 对IOS设备中UDID的一些思考

    本文转载至 http://blog.csdn.net/happyrabbit456/article/details/11565209 http://blog.csdn.net/xiaoguan2008 ...

  5. centos7的nfs配置

    author : headsen chen date : 2018-04-12  09:40:14  一,服务端安装和配置: 环境准备: systemctl stop firewalld system ...

  6. xmpp muc 群聊协议 1

    翻译来自 :http://wiki.jabbercn.org/index.php?title=XEP-0045&variant=zh-cn#.E6.9C.AF.E8.AF.AD 通用术语 Af ...

  7. 爬虫入门【9】Python链接Excel操作详解-openpyxl库

    Openpyx是一个用于读写Excel2010各种xlsx/xlsm/xltx/xltm文件的python库. 现在大多数用的都是office2010了,如果之前之前版本的可以使用xlrd读,xlwt ...

  8. bootstrap 媒体查询

    //各类设备的分辨率 /*超小设备(手机,小于768px)*/ /* Bootstrap 中默认情况下没有媒体查询 */ /*超小型设备(小于768px)*/ @media (min-width:@s ...

  9. Android Download机制详解(一)DocumentUI部分

    在Android中Google为我们集成了一套十分便利的Download机制,用来下载网络上的资源文件.以此省去了我们编写和维护大量与Download相关的代码. 组成 Android中Downloa ...

  10. MyBatis 映射文件详解

    1. MyBatis 映射文件之<select>标签 <select>用来定义查询操作; "id": 唯一标识符,需要和接口中的方法名一致; paramet ...