Question on calling this const value

Hi,
I am new to js and have a requirement to store a value in a const in javascript. The value is computed i.e. it needs a function. I have the following code:

const test = [] = function() { } 

However, I am wondering, how can I test this? I tried to run my js file with this in webstorm but i can’t get an output, even with a console.log method.

Any ideas/

That code is already confusing with the multiple assignments.

I would have the function separate, and return the array that is needed.

function nameOfFunction() {
    return [];
}
const test = nameOfFunction();

You can then check that the function does what it needs to do, and also check that the test variable has been suitably assigned.

1 Like

Ah ok yeah that would do! That way all of that in my js file I can easily run it and test. :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.