Reputation: 150614
I have read now for a number of times that a default export is actually just a named export with the name default
. Now this makes me wonder what the behavior is when mixing default and named exports: Usually, they play nicely together. But what if I define a default export, and a named export named default
?
What is the intended behavior of the runtime / compiler here?
Upvotes: 1
Views: 108
Reputation: 37755
Any reserved keyword can not be used as variable name ( identifier ),default
is a keyword so you can't use it as variable name, interpreter will trow error
The error statement depends on browser
SyntaxError: The use of a future reserved word for an identifier is invalid (Edge)
SyntaxError: "x" is a reserved identifier (Firefox)
SyntaxError: Unexpected reserved word (Chrome)
when you try this
export const default = {some: value}
Upvotes: 2
Reputation: 370619
a named export named default
This is not possible, because default
is a reserved keyword. If you try to do something like
export const default = 'bar';
or try to name a variable default
and then export it
const default = 'bar';
export default;
the interpreter will throw a SyntaxError and refuse to continue parsing.
So, no such collisions are possible.
Upvotes: 5