1

Is this valid export syntax?

export default debug = {
    myfunction: myFunction
};
1
  • Yes it is valid syntax. Commented Feb 23, 2017 at 4:25

2 Answers 2

5

Default export syntax is correct.

But one catch here the variable 'debug' needs to be decalred.

You do something like below:

export default {
    myfunction: myFunction
}

or

const deb = {
    myfunction: myFunction
}
export default deb;
Sign up to request clarification or add additional context in comments.

Comments

4

As debug is not defined when you assign your export object to it, and modules are run in strict mode, no. This is not valid. If you feel you must export a named object, you must declare it first.

let debug;
export default debug = {};

Note that you cannot declare the variable and export it in the same line.

export default const debug = {}; // invalid

From MDN:

Note that it is not possible to use var, let or const with export default.

4 Comments

Thank you. I was asking because I was building this with jspm and it did complain about "debug" not being defined. I ended up doing what you posted.
"Valid in that it will run? Yes." Not quite. Since modules are in strict mode and you cannot assign to undeclared variables in strict mode, this will throw a runtime error.
@FelixKling thanks, I'm so used to working with transpilers I completely forgot about that. Answer fixed.
Thanks to you both for clarifying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.