Difference between export default myVar and export default myFunc()












1















Is there any perf difference between:



const myVar = myFunc()
export default myVar


and:



export default myFunc()


I prefer the 2nd notation (more concise, less code), but I don't know if it has an impact on performance. Each code loading this module will point to the same reference, or to a new one ?










share|improve this question























  • It's the same myFunc() will only be called once.

    – Keith
    Nov 13 '18 at 12:15






  • 1





    "Each code loading this module will point to the same reference, or to a new one ?" Modules are always only evaluated once (the first time they are loaded).

    – Felix Kling
    Nov 13 '18 at 17:23
















1















Is there any perf difference between:



const myVar = myFunc()
export default myVar


and:



export default myFunc()


I prefer the 2nd notation (more concise, less code), but I don't know if it has an impact on performance. Each code loading this module will point to the same reference, or to a new one ?










share|improve this question























  • It's the same myFunc() will only be called once.

    – Keith
    Nov 13 '18 at 12:15






  • 1





    "Each code loading this module will point to the same reference, or to a new one ?" Modules are always only evaluated once (the first time they are loaded).

    – Felix Kling
    Nov 13 '18 at 17:23














1












1








1








Is there any perf difference between:



const myVar = myFunc()
export default myVar


and:



export default myFunc()


I prefer the 2nd notation (more concise, less code), but I don't know if it has an impact on performance. Each code loading this module will point to the same reference, or to a new one ?










share|improve this question














Is there any perf difference between:



const myVar = myFunc()
export default myVar


and:



export default myFunc()


I prefer the 2nd notation (more concise, less code), but I don't know if it has an impact on performance. Each code loading this module will point to the same reference, or to a new one ?







javascript ecmascript-6 export






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 12:13









soywodsoywod

1,5711819




1,5711819













  • It's the same myFunc() will only be called once.

    – Keith
    Nov 13 '18 at 12:15






  • 1





    "Each code loading this module will point to the same reference, or to a new one ?" Modules are always only evaluated once (the first time they are loaded).

    – Felix Kling
    Nov 13 '18 at 17:23



















  • It's the same myFunc() will only be called once.

    – Keith
    Nov 13 '18 at 12:15






  • 1





    "Each code loading this module will point to the same reference, or to a new one ?" Modules are always only evaluated once (the first time they are loaded).

    – Felix Kling
    Nov 13 '18 at 17:23

















It's the same myFunc() will only be called once.

– Keith
Nov 13 '18 at 12:15





It's the same myFunc() will only be called once.

– Keith
Nov 13 '18 at 12:15




1




1





"Each code loading this module will point to the same reference, or to a new one ?" Modules are always only evaluated once (the first time they are loaded).

– Felix Kling
Nov 13 '18 at 17:23





"Each code loading this module will point to the same reference, or to a new one ?" Modules are always only evaluated once (the first time they are loaded).

– Felix Kling
Nov 13 '18 at 17:23












2 Answers
2






active

oldest

votes


















1














There is no difference in this case.



You simply use an alias.



So the reference will be the same each time.






share|improve this answer
























  • Okey, and is the 2nd considered as a bad practice ? I don't see this often, but I like the idea. Even with export default function() { ... }, but seems not so common.

    – soywod
    Nov 14 '18 at 8:28











  • @soywod The most common (and good, my opinion) practice is to export 1 object from a file, which contents a list of props. So you will have a singleton interface for a file. And all your imports will have the same structure. And they are expandable better. As for exporting only 1 thing for a file it's no a big sence if you use 1st or 2nd, but the better option will be an object with 1 field (for same import/export structure)

    – Eugene Mihaylin
    Nov 14 '18 at 9:07













  • I see it a bit differently. The fact to use default export force yourself to apply the Single Responsibility pattern. I have never more than one export to do by file (except for types in fact, so I use import myFunc, {MyType} from ...). That why I often use the default, and that's why I came to this export default function() { ... }.

    – soywod
    Nov 14 '18 at 10:26



















1














You can find really good explanations here:
https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export#Using_the_default_export
and
What is "export default" in javascript?






share|improve this answer



















  • 2





    Link only answers are considered poor quality. It also doesn't seem to address the question.

    – Felix Kling
    Nov 13 '18 at 17:21













  • I know how import / export works, this is not answering my question.

    – soywod
    Nov 14 '18 at 8:27











  • @soywod Apologies then, note taken.

    – squeekyDave
    Nov 14 '18 at 9:23











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280782%2fdifference-between-export-default-myvar-and-export-default-myfunc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














There is no difference in this case.



You simply use an alias.



So the reference will be the same each time.






share|improve this answer
























  • Okey, and is the 2nd considered as a bad practice ? I don't see this often, but I like the idea. Even with export default function() { ... }, but seems not so common.

    – soywod
    Nov 14 '18 at 8:28











  • @soywod The most common (and good, my opinion) practice is to export 1 object from a file, which contents a list of props. So you will have a singleton interface for a file. And all your imports will have the same structure. And they are expandable better. As for exporting only 1 thing for a file it's no a big sence if you use 1st or 2nd, but the better option will be an object with 1 field (for same import/export structure)

    – Eugene Mihaylin
    Nov 14 '18 at 9:07













  • I see it a bit differently. The fact to use default export force yourself to apply the Single Responsibility pattern. I have never more than one export to do by file (except for types in fact, so I use import myFunc, {MyType} from ...). That why I often use the default, and that's why I came to this export default function() { ... }.

    – soywod
    Nov 14 '18 at 10:26
















1














There is no difference in this case.



You simply use an alias.



So the reference will be the same each time.






share|improve this answer
























  • Okey, and is the 2nd considered as a bad practice ? I don't see this often, but I like the idea. Even with export default function() { ... }, but seems not so common.

    – soywod
    Nov 14 '18 at 8:28











  • @soywod The most common (and good, my opinion) practice is to export 1 object from a file, which contents a list of props. So you will have a singleton interface for a file. And all your imports will have the same structure. And they are expandable better. As for exporting only 1 thing for a file it's no a big sence if you use 1st or 2nd, but the better option will be an object with 1 field (for same import/export structure)

    – Eugene Mihaylin
    Nov 14 '18 at 9:07













  • I see it a bit differently. The fact to use default export force yourself to apply the Single Responsibility pattern. I have never more than one export to do by file (except for types in fact, so I use import myFunc, {MyType} from ...). That why I often use the default, and that's why I came to this export default function() { ... }.

    – soywod
    Nov 14 '18 at 10:26














1












1








1







There is no difference in this case.



You simply use an alias.



So the reference will be the same each time.






share|improve this answer













There is no difference in this case.



You simply use an alias.



So the reference will be the same each time.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 12:17









Eugene MihaylinEugene Mihaylin

9581424




9581424













  • Okey, and is the 2nd considered as a bad practice ? I don't see this often, but I like the idea. Even with export default function() { ... }, but seems not so common.

    – soywod
    Nov 14 '18 at 8:28











  • @soywod The most common (and good, my opinion) practice is to export 1 object from a file, which contents a list of props. So you will have a singleton interface for a file. And all your imports will have the same structure. And they are expandable better. As for exporting only 1 thing for a file it's no a big sence if you use 1st or 2nd, but the better option will be an object with 1 field (for same import/export structure)

    – Eugene Mihaylin
    Nov 14 '18 at 9:07













  • I see it a bit differently. The fact to use default export force yourself to apply the Single Responsibility pattern. I have never more than one export to do by file (except for types in fact, so I use import myFunc, {MyType} from ...). That why I often use the default, and that's why I came to this export default function() { ... }.

    – soywod
    Nov 14 '18 at 10:26



















  • Okey, and is the 2nd considered as a bad practice ? I don't see this often, but I like the idea. Even with export default function() { ... }, but seems not so common.

    – soywod
    Nov 14 '18 at 8:28











  • @soywod The most common (and good, my opinion) practice is to export 1 object from a file, which contents a list of props. So you will have a singleton interface for a file. And all your imports will have the same structure. And they are expandable better. As for exporting only 1 thing for a file it's no a big sence if you use 1st or 2nd, but the better option will be an object with 1 field (for same import/export structure)

    – Eugene Mihaylin
    Nov 14 '18 at 9:07













  • I see it a bit differently. The fact to use default export force yourself to apply the Single Responsibility pattern. I have never more than one export to do by file (except for types in fact, so I use import myFunc, {MyType} from ...). That why I often use the default, and that's why I came to this export default function() { ... }.

    – soywod
    Nov 14 '18 at 10:26

















Okey, and is the 2nd considered as a bad practice ? I don't see this often, but I like the idea. Even with export default function() { ... }, but seems not so common.

– soywod
Nov 14 '18 at 8:28





Okey, and is the 2nd considered as a bad practice ? I don't see this often, but I like the idea. Even with export default function() { ... }, but seems not so common.

– soywod
Nov 14 '18 at 8:28













@soywod The most common (and good, my opinion) practice is to export 1 object from a file, which contents a list of props. So you will have a singleton interface for a file. And all your imports will have the same structure. And they are expandable better. As for exporting only 1 thing for a file it's no a big sence if you use 1st or 2nd, but the better option will be an object with 1 field (for same import/export structure)

– Eugene Mihaylin
Nov 14 '18 at 9:07







@soywod The most common (and good, my opinion) practice is to export 1 object from a file, which contents a list of props. So you will have a singleton interface for a file. And all your imports will have the same structure. And they are expandable better. As for exporting only 1 thing for a file it's no a big sence if you use 1st or 2nd, but the better option will be an object with 1 field (for same import/export structure)

– Eugene Mihaylin
Nov 14 '18 at 9:07















I see it a bit differently. The fact to use default export force yourself to apply the Single Responsibility pattern. I have never more than one export to do by file (except for types in fact, so I use import myFunc, {MyType} from ...). That why I often use the default, and that's why I came to this export default function() { ... }.

– soywod
Nov 14 '18 at 10:26





I see it a bit differently. The fact to use default export force yourself to apply the Single Responsibility pattern. I have never more than one export to do by file (except for types in fact, so I use import myFunc, {MyType} from ...). That why I often use the default, and that's why I came to this export default function() { ... }.

– soywod
Nov 14 '18 at 10:26













1














You can find really good explanations here:
https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export#Using_the_default_export
and
What is "export default" in javascript?






share|improve this answer



















  • 2





    Link only answers are considered poor quality. It also doesn't seem to address the question.

    – Felix Kling
    Nov 13 '18 at 17:21













  • I know how import / export works, this is not answering my question.

    – soywod
    Nov 14 '18 at 8:27











  • @soywod Apologies then, note taken.

    – squeekyDave
    Nov 14 '18 at 9:23
















1














You can find really good explanations here:
https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export#Using_the_default_export
and
What is "export default" in javascript?






share|improve this answer



















  • 2





    Link only answers are considered poor quality. It also doesn't seem to address the question.

    – Felix Kling
    Nov 13 '18 at 17:21













  • I know how import / export works, this is not answering my question.

    – soywod
    Nov 14 '18 at 8:27











  • @soywod Apologies then, note taken.

    – squeekyDave
    Nov 14 '18 at 9:23














1












1








1







You can find really good explanations here:
https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export#Using_the_default_export
and
What is "export default" in javascript?






share|improve this answer













You can find really good explanations here:
https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export#Using_the_default_export
and
What is "export default" in javascript?







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 13:37









squeekyDavesqueekyDave

373114




373114








  • 2





    Link only answers are considered poor quality. It also doesn't seem to address the question.

    – Felix Kling
    Nov 13 '18 at 17:21













  • I know how import / export works, this is not answering my question.

    – soywod
    Nov 14 '18 at 8:27











  • @soywod Apologies then, note taken.

    – squeekyDave
    Nov 14 '18 at 9:23














  • 2





    Link only answers are considered poor quality. It also doesn't seem to address the question.

    – Felix Kling
    Nov 13 '18 at 17:21













  • I know how import / export works, this is not answering my question.

    – soywod
    Nov 14 '18 at 8:27











  • @soywod Apologies then, note taken.

    – squeekyDave
    Nov 14 '18 at 9:23








2




2





Link only answers are considered poor quality. It also doesn't seem to address the question.

– Felix Kling
Nov 13 '18 at 17:21







Link only answers are considered poor quality. It also doesn't seem to address the question.

– Felix Kling
Nov 13 '18 at 17:21















I know how import / export works, this is not answering my question.

– soywod
Nov 14 '18 at 8:27





I know how import / export works, this is not answering my question.

– soywod
Nov 14 '18 at 8:27













@soywod Apologies then, note taken.

– squeekyDave
Nov 14 '18 at 9:23





@soywod Apologies then, note taken.

– squeekyDave
Nov 14 '18 at 9:23


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280782%2fdifference-between-export-default-myvar-and-export-default-myfunc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine