Uncaught in promise TypeError Cannot read properties of undefined reading duration at HTMLButtonElementanonymous
This error message usually occurs when trying to access a property or method of an undefined value. In this case, the code is trying to access the 'duration' property of an undefined value.
To fix this error, you need to check if the value is defined before trying to access its properties or methods. You can use an if statement or a nullish coalescing operator (??) to check if the value is defined before accessing its properties or methods.
For example, instead of directly accessing the 'duration' property of a variable, you can use the nullish coalescing operator to provide a default value in case the variable is undefined:
const duration = myVariable?.duration ?? 0;
This code checks if 'myVariable' is defined and has a 'duration' property. If it does, it assigns the value of 'duration' to the 'duration' variable. If 'myVariable' is undefined or doesn't have a 'duration' property, it assigns the default value of 0 to the 'duration' variable.
原文地址: http://www.cveoy.top/t/topic/bmJR 著作权归作者所有。请勿转载和采集!