When we try to access an undefined variable it always returns undefined and we cannot get or set any property of undefined. In that case, an application will throw ” Uncaught TypeError cannot set property of undefined”.

In the above error test object is undefined and does not exist. If the object does not exist ,error will throw “Uncaught Type Error cannot set property of undefined.”
To avoid this type of errors, objects needs to be defined before using and also a good static type checking system could help to avoid them if Strict compiler option is used.