当脚本遇到未初始化的变量或对象时,通常会抛出如上图所示的错误。

Decription

'Undefined'是全局对象的属性。如果没有为变量赋值,则为'undefined'类型。当求值变量没有任何赋值时,代码也会返回未定义的值。

Code structure

function test(t) {      //defining a function
if (t === undefined) { //if t=undefined, call tt
console.log(t.tt) //call tt member from t
}
return t;
}
var a; //a is a variable with undefined value
console.log(test(a)); //function call

Error

运行以上代码后,将会看到一个错误提示:

Debugging

需要在代码中判断是否变量是 undefined

if (typeof(jsvariable) == 'undefined') {
...
}

https://codeburst.io/uncaught-typeerror-cannot-read-property-of-undefined-in-javascript-c81e00f4a5e3

Uncaught TypeError: Cannot read property of undefined In JavaScript的更多相关文章

  1. Uncaught TypeError: Cannot read property 'msie' of undefined

    因为图方便,抄了别人写的一个jquerry插件,运行时“var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ...

  2. easyui使用时出现这个Uncaught TypeError: Cannot read property 'combo' of undefined

    easyui使用时出现这个Uncaught TypeError: Cannot read property 'nodeName' of undefined 最后检查发现是必须给select一个id,光 ...

  3. reactjs Uncaught TypeError: Cannot read property 'location' of undefined

    reactjs Uncaught TypeError: Cannot read property 'location' of undefined reactjs 路由配置 怎么跳转 不成功 国内搜索引 ...

  4. index.js:13 Uncaught TypeError: Cannot read property 'split' of undefined

    使用 webpack 编译 Vue 项目时出现报错: index.js:13 Uncaught TypeError: Cannot read property 'split' of undefined ...

  5. Uncaught TypeError: Cannot read property ‘split’ of undefined

    问题 :Uncaught TypeError: Cannot read property ‘split’ of undefinedat HTMLLIElement. split()切割的问题 因为遍历 ...

  6. SignalR代理对象异常:Uncaught TypeError: Cannot read property 'client' of undefined 推出的结论 SignalR 简单示例 通过三个DEMO学会SignalR的三种实现方式 SignalR推送框架两个项目永久连接通讯使用 SignalR 集线器简单实例2 用SignalR创建实时永久长连接异步网络应用程序

    SignalR代理对象异常:Uncaught TypeError: Cannot read property 'client' of undefined 推出的结论   异常汇总:http://www ...

  7. DataTable插件报错:Uncaught TypeError: Cannot read property 'style' of undefined

    DataTable插件报错:Uncaught TypeError: Cannot read property 'style' of undefined 原因:table 中定义的列和aoColumns ...

  8. underscore.js定义模板遇到问题:Uncaught TypeError: Cannot read property 'replace' of undefined

    代码正确缩进位置如下, extend "layout" block 'content',-> div ->'nihao' script id:"Invoice ...

  9. Uncaught TypeError: Cannot read property 'decimalSeparator' of undefined

    1.错误描述 jquery.jqGrid.min.js:477 Uncaught TypeError: Cannot read property 'decimalSeparator' of undef ...

随机推荐

  1. SQLServer从其他表获取的数据更新该表的一部分

    在网上常见的是update  a  set  username  =  username  FROM b  on a.userid=b.userid,该更新语句是对a表中所有行进行更新.如果只更新一部 ...

  2. 重置SQLSERVER表的自增列,让自增列重新计数【转】

    很多时候我们需要重置某个表的自增列,让自增列重新从1开始记数.最蠢的方法当然是把该表删掉再重新建表了.其实,还有其它的方法可以重置自增列的值: 方法一:使用TRUNCATE TABLE语句: TRUN ...

  3. 巧用netsh命令实现端口转发(端口映射)不求人

    好处:即时生效,随意修改删除,不影响其他ip映射 记事本保存为bat格式批量添加后,并查看映射: netsh interface portproxy add v4tov4 listenport=701 ...

  4. char*、string、CString各种字符串之间转换

    参考博客: http://blog.csdn.net/luoweifu/article/details/20242307 http://blog.csdn.net/luoweifu/article/d ...

  5. raspberrypi&linux

    Raspberrypi&linux 2018-01-23 19:54:01 Let's go!

  6. IOS DatePicker 和 UIBarButtonItem 常用属性

    - (void)viewDidLoad { [super viewDidLoad]; // // self.inputTextField.inputView = [[UISwitch alloc ] ...

  7. C#赋值运算符

    一.C#赋值运算符 C#语言的赋值运算符用于将一个数据赋予一个变量.属性或者引用.数据可以是常量.变量或者表达式. 1. 简单赋值 “=”操作符被称为简单赋值操作符.在一个简单赋值中,右操作数必须为某 ...

  8. Springboot端口设置

    application.properties 加入 server.port=80

  9. vue 自定义动态弹框

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. c语言中--typeof--关键字用法

    C语言中 typeof 关键字是用来定义变量数据类型的.在linux内核源代码中广泛使用. 下面是Linux内核源代码中一个关于typeof实例: #define min(x, y) ({ \ typ ...