what is the difference between import and const and which is preferred in commonjs

后端 未结 1 1865
难免孤独
难免孤独 2021-02-05 04:44

I have noticed a bit of switching between using const and import for referencing libraries in node.js applications using es6 syntax with Babel.

What is the preferred met

1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 05:20

    What is the preferred method and what is the difference between using const and import?

    In 2016 it makes sense to stick with the import since that's the part of the standard.

    There is no technical reason to prefer import over require though: everything that can be done using require can be done with import and vice versa. In some cases one will be more concise, in another - the other.

    To summarise: choose the one that fits the project code conventions/consistency.

    0 讨论(0)
提交回复
热议问题