TypeError: Cannot read properties of undefined (reading 'num')" found in
时间: 2023-07-01 17:28:32 浏览: 126
This error message typically occurs when you try to access a property or method of an undefined variable.
For example, if you have the following code:
```
let obj;
console.log(obj.num);
```
You will get the "TypeError: Cannot read properties of undefined (reading 'num')" error because the `obj` variable is undefined and does not have a `num` property.
To fix this error, you need to make sure that the variable you are trying to access is defined and has the property or method you are trying to use. You can do this by checking if the variable is not undefined before accessing its properties or methods. For example:
```
let obj = { num: 42 };
if (obj !== undefined) {
console.log(obj.num);
}
```
This code will only try to access the `num` property if `obj` is defined, preventing the error from occurring.
阅读全文