One of my most often used methods is the Object.prototype.hasOwnProperty() to check if the object has a specific property.
This allows you to avoid reference exceptions.
Note: Make sure you use this by calling the method from the Object prototype like this: Object.hasOwnProperty.call(obj, "property")
Why you might ask? It is because if the object you are trying to call this method from is null you will run into an exception. By making use of call you can avoid this from happening.
A very rare scenario would also be that if you call hasOwnProperty from the object itself, the method could have been mutated.
Enjoy :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
One of my most often used methods is the Object.prototype.hasOwnProperty() to check if the object has a specific property.
This allows you to avoid reference exceptions.
Note: Make sure you use this by calling the method from the Object prototype like this: Object.hasOwnProperty.call(obj, "property")
Why you might ask? It is because if the object you are trying to call this method from is null you will run into an exception. By making use of call you can avoid this from happening.
A very rare scenario would also be that if you call hasOwnProperty from the object itself, the method could have been mutated.
Enjoy :)