js undefined error All In One
js undefined error All In One
Uncaught TypeError: Cannot read property 'key' of undefined
OK ✅
const num = 1;
// 1
num.key;
// undefined
(1).key;
// undefined
Error ❌
const u = undefined;
u.key;
// Uncaught TypeError: Cannot read property 'key' of undefined
demo
const arr = [1, 2, 3];
const uid = 2;
// no error ✅, but bug ❌
const index = arr.findIndex(item => item.id === uid);
// undefined value bug ❌
const arr = [undefined, 1, 2, 3];
const uid = 2;
// error ❌ & bug ❌
const index = arr.findIndex(item => item.id === uid);
Uncaught TypeError: Cannot read property 'id' of undefined
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex
refs
TypeError
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14979781.html
未经授权禁止转载,违者必究!