From the course: JavaScript: Best Practices for Functions and Classes

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Default export constants when possible

Default export constants when possible - JavaScript Tutorial

From the course: JavaScript: Best Practices for Functions and Classes

Start my 1-month free trial

Default export constants when possible

- [Instructor] ES6 module syntax is flexible providing a few different ways to specify, export and import code, especially when you're working on a team. Consistency can save time when you're creating and using modules, no matter which syntax you settle on. One popular approach is to ensure that you use const when creating exports. There are already a lot of reasons to prefer const over let or VAR for most JavaScript, whether in modules or elsewhere but a module is meant to be consistently reusable. So a module should provide a common predictable interface in multiple contexts. If an import is mutable however, your code can make changes whether intentional or not, which could result in unexpected results in later code that works with the module. The start file for this video includes the distanceTo module, to calculate the distance between two points. The function is declared with let, which is not what I want. There's…

Contents