<script type="text/javascript">
var outObj = {
type :"java"
}
function innerM(){
var p;
alert(p);//undefined
alert("k:"+k);//error--innerObj未定义
alert(outObj.jack);//undefined
alert(innerObj.jack);//error--innerObj未定义
} innerM(); </script>
<script type="text/javascript">
alert(typeof(false) === 'boolean'); //true
alert(typeof(0) === 'number'); //true
alert(typeof("") === 'string'); //true
alert(typeof(null) === 'object'); //true
alert(typeof undefined === 'undefined'); //true
</script>
 <script type="text/javascript">
alert(false == undefined); //false
alert(false == null); //false
alert(false == 0); //true
alert(false == ""); //true
alert(null == undefined); //true
</script>
<script type="text/javascript">
alert(false.toString()); // "false"
alert("".charAt(0)); // ""
alert((0).toExponential(10)); // 0.0000000e+0
alert(undefined.toString()); // throw exception "undefined has no properties"
alert(null.toString()); // "null has no properties"
</script>
 <script type="text/javascript">
alert(String(false)); // "false"
alert(String("")); // ""
alert(String(0)); // 0.0000000e+0
alert(String(undefined)); // "undefined"
alert(String(null)); // "null" alert(decodeURI(undefined));// "undefined"
alert(decodeURI(null));// "null"
</script>
 <script type="text/javascript">
//假值和空值作为if条件分支
//假值和空值有一个共性,那就是在 作为if的条件分支时,均被视为false ;应用"!"操作之后得到的均为true。
//这是因为,这几个对象均被视为各自类型中的无效值或空值。因此if分支中这些对象均被视为false对待。如下示例代码:
var ar = [undefined,false,0,"",null];
for(var i = 0,len = ar.length; i < len; i++){
if(ar[i]){
alert("你不应该看到此对话框!");
}
}
</script>

<script type="text/javascript">
//undefined和null对象无非是两个特殊对象,undefined表示无效对象,null表示空对象。
//如果变量显式或者隐式(由Javascript引擎进行赋值)地被赋予了undefined,
//那么代表了此变量未被定义,如果被赋予null值,则代表此变量被初始化为空值。
//在Javascript中,变量是通过var声明,=赋值符进行定义(初始化变量所指向的对象)。
//当然,如果声明一个全局变量(作为window属性)可以不使用var关键字。变量可以在声明的同时进行定义。
//变量如果声明了但是没有初始化,那么Javascript引擎会将此变量自动指向undefined对象。
//这里需要注意,我们在上面引用window.abcd时,弹出的是undefined;而直接引用abcd变量时,却抛出了一个异常。
//这是由于Javascript引擎对于没有显式指定对象链的变量,会尝试从最近的作用域开始查找变量,
//查找失败,则退到父级作用链进行查找。如果均查找失败,则抛出"变量未定义"的异常。 var undefinedVariable,nullVariable = null;
alert(undefinedVariable); // "undefined"
alert(window.undefinedVariable); // "undefined"
alert(window.abcd); // "undefined"
alert(nullVariable); // "null"
alert(abcd); // throw exception "abcd is not defined"
</script>
 <script type="text/javascript">
//这两个值在进行数字运算的时候也有不同。
alert(1+undefined); // "NaN"
alert(1+null); // "1"
</script>
<script type="text/javascript">
alert("!undefined......" + (!undefined));
alert("undefined==false......" + (undefined==false));
</script>

jjs 产生undefined的情况的更多相关文章

  1. JS下计算当前日期(当天)后N天出现NAN或者undefined的情况

    前言: 帮客户做一个订单系统,需要一个日期1,一个日期2,默认情况下日期1为当天,日期2为明天,只是当时有些疑惑的是日期2偶尔会出现NAN的情况,今天在segmentfault.com看到了同样的问题 ...

  2. [Effective JavaScript 笔记]第54条:将undefined看做“没有值”

    undefined值很特殊,每当js无法提供具体的值时,就会产生undefined. undefined值场景 未赋值的变量的初始值即为undefined. var x; x;//undefined ...

  3. undefined类型

    undefined类型 只有一个特殊的值 undefined   在使用var声明变量但未对其加以初始化,这个变量的值就是undefined 值是undefined的情况: 1.显示声明并初始化变量值 ...

  4. 关于js中undefined的判断

    在开发中遇到一个情景,当添加用户的时候不需要传入用户id,如果是修改那么需要传入id,因为用的是angular框架,参数是早就定义好了的,那么在新增用户的时候就会出现undefined的情况,之前我一 ...

  5. JavaScript推断undefined的技巧

    两种方法: 处理变量为undefined的情况: v = v||null;    //假设v为undefined,则其值变为null 双感叹号:!!,把null/undifined/0转换为bolle ...

  6. 数据类型总结——null和undefined

    相关文章 简书原文:https://www.jianshu.com/p/c3e252efe848 数据类型总结——概述:https://www.cnblogs.com/shcrk/p/9266015. ...

  7. 处理 JS中 undefined 的 7 个技巧

    摘要: JS的大部分报错都是undefined... 作者:前端小智 原文:处理 JS中 undefined 的 7 个技巧 Fundebug经授权转载,版权归原作者所有. 大约8年前,当原作者开始学 ...

  8. ie ajax 跨域情况遇到的各种问题

    jQuery.support.cors = true; http://blog.csdn.net/jupiter37/article/details/25694289 jQuery ajax跨域调用出 ...

  9. ?.可选链操作符( ?. ) 可选链运算符可防止抛出 TypeError: Cannot read property ’xxx' of undefined。

    可选链操作符( ?. )允许读取位于连接对象链深处的属性的值,而不必明确验证链中的每个引用是否有效.?. 操作符的功能类似于 . 链式操作符,不同之处在于,在引用为空(nullish ) (null ...

随机推荐

  1. sqlserver数据库三范式的理解

    从来都是听过概念,过一段时间就忘记了,根本就没有深入的理解.这次梳理一遍,用自己的方式记录一下. 1nf 原子性,不可拆分性 例如一张表里包含一个class属性(软件系,外语系,经贸系...)字段,这 ...

  2. Hadoop安装(2)安装hadoop 前的centos 设置

    将虚拟机网络连接设为:Bridged 添加用户:hadoop,设置密码.关闭防火墙,selinux.暂且不关闭不需要的任务. 参照:http://www.cnblogs.com/xia520pi/ar ...

  3. Poem: Reserverd Words

    Let this long package float, Goto private class if short. While protected with debugger case, Contin ...

  4. hibernate异常

    <h1> nested exception is org.hibernate.LazyInitializationException:</h1> stackoverflow:h ...

  5. JNI加载Native Library 以及 跨线程和Qt通信

    Part1 Java Native Interface-JNI-JAVA本地调用 JNI标准是Java平台的一部分, 允许Java代码和其他语言进行交互; 开始实现-> Step 1) 编写Ja ...

  6. Java内部类总结

    内部类是一种编译器现象,与虚拟机无关.编译器将会把内部类翻译成用美元符号$分隔外部类名与内部类名的常规类文件,而虚拟机对此一无所知.编译器为了引用外部类,生成了一个附加的实例域this$0 为什么要用 ...

  7. yii2 安装过程中的问题及解决方法

    一.php版本要求5.4+,如果使用wamp组合包,建议更换 二.各种模块的支持,一般只要修改php.ini文件,去掉相应模块前的注释即可. 注意,Intl extension模块的支持需要将     ...

  8. 初学swift笔记 流程控制(五)

    import Foundation ; i<=; i++ { println(i) } let str1="adl;fjasdfl;ouewrouqwperuadf" for ...

  9. 嵌入式平台使用gtest进行白盒测试

    看了coderzh大神写的gtest(http://www.cnblogs.com/coderzh/archive/2009/04/06/1426755.html)使用的帖子,觉得gtest这个工具比 ...

  10. VS2012中的全部预定义键盘快捷键列表

    原文 http://www.elanblog.com/2013/05/14/vs2012-key-list/#sectionToggle7 Visual Studio 集成开发环境 (IDE) 包括若 ...