'What does mean "export default {}" without name

I found react native module with code like this:

export default {
    activateWithApiKey(apiKey: string) {
        AppMetrica.activateWithApiKey(apiKey);
    },
};

It is strange that "export default" doesn't have name. All of the examples from google search has "export default SomeName". Does anybody know what "export default" without name means? Thank you for help.



Solution 1:[1]

Referring to default exports syntax:

// Default exports
export default expression;
export default function (…) { … } // also class, function*
export default function name1(…) { … } // also class, function*
export { name1 as default, … };

As you can see, name could be specified for function, class, function* (e.g. export default class Component).

This option is usually used when you need the exported function further in the current module. Pay attention, if you specify the name for export default, you still can use another name during the import. For example, function is exported and can be used further in current module:

// module-a.js
export default function originalName() { console.log('i am default') };

originalName();

// module-b.js
import someAnotherName from './module-a.js'

Answering your question

Does anybody know what "export default" without name means?

export default expression; means expression name could be missed on export phase:

// module-a.js
export default {
    activateWithApiKey(apiKey: string) {
        AppMetrica.activateWithApiKey(apiKey);
    },
};

// module-b.js
import anyName from './module-a.js' 
// creates local variable `anyName` and assigns object from 'module-a.js` to it

Solution 2:[2]

Trying to be short and direct i'd say.

When you specify the name in export default SomeName Then SomeName has to be used when you import as the name of the variable. However when you only write export default { //some code } then, when you do the import, you can use whatever name for the variable that will comtain the exported object.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 mtaDev