Skip to content
Advertisement

Javascrip default parameter ReferenceError: param is not defined

I have a function defined to fetch some data. I set default parameters like this:

JavaScript

I import this function in my component and use it like so:

JavaScript

It works without setting limit and offset, but when I try to pass new values for offset and limit, I get an Unhandled Runtime Error ReferenceError: limit/offset is not defined. Am I missing something?

Advertisement

Answer

If you call an function, you do not “set” the “parameternames”.
You just simpliy parse in the Numbers/Data which you want to use inside your function.

So your function call should look like this:

JavaScript

and if you want to use the same parameter (in your case someData) again, you do not “re set” the variabletype. You simpily override the existing data.

so in your case your componentDidMount will look like this:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement