Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up[guide]Fix Type Error issue occur because of default value of function… #2148
Conversation
… argument.
|
While this is accurate, this isn't often a problem in practice, and using |
I think we should below code to check whether opts variable contain object or not.
|
|
That would be most robust, but in this case the error from passing null is desired, because that’s not how the function is intended to be used. I think this example is good as is. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.


mhjariwala commentedJan 5, 2020
In javascript style guide, According to rule 7.7, if i trying to access property key of opts by using dot notation(.) or square bracket([]) there is chances of type error.
Why?
Because, if opts receive null value when 'handleThings' function invoked then default value empty object({}) not assign to the opts argument. So, this is happen then user will get uncaught type error.
Example:
When you run this code you will get an error called "Uncaught TypeError: Cannot read property 'notificationEnabled' of null".