一、 前言
因为对JavaScript中的 null\undefined\” 有些分不清楚,因此在试验之后进行一下小结。
二、 源码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JavaScript---Linux公社www.linuxidc.com</title>
<script type="text/javascript" charset="utf-8">
var a;
var b = null;
var c = {};
var d = '';
console.log(x); //报错
console.log(a); //undefined
console.log(b); //null
console.log(c.somevalue); //undefined
console.log(d); //
console.log(!a, !b, !d); //true true true
</script>
</head>
<body>
</body>
</html>
三、 总结
1.未定义变量: 使用会报错
2.声明变量未赋值: 变量为undefined
3.声明变量并赋值为null: 变量为null
4.对象中未声明的变量:变量为undefined
5.空字符串:变量为”
6.null\undefined\” 的非: 均为true
JavaScript高级程序设计(第3版)高清完整PDF中文+英文+源码 下载见 http://www.linuxidc.com/Linux/2014-09/107426.htm
如何使用JavaScript书写递归函数 http://www.linuxidc.com/Linux/2015-01/112000.htm
JavaScript核心概念及实践 高清PDF扫描版 (邱俊涛) http://www.linuxidc.com/Linux/2014-10/108083.htm
理解JavaScript中的事件流 http://www.linuxidc.com/Linux/2014-10/108104.htm
JavaScript跨浏览器事件对象类库 http://www.linuxidc.com/Linux/2015-07/120615.htm
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-08/121282.htm