Saturday, May 18, 2019

Javascript Basics : Difference between require and imports in javascript.

It relates to JavaScript modules. JavaScript code can be broken down into modules (which you require), but each module can “export” different things. You use import to specify what you want to, well, import from a module.

So say you had an imaginary shapes module, that exports a Circle and a Rectangle class. If you did require shapes it would import everything from that module. Instead, you can use import to only, well, import specific items from a module. So if you only wanted the Circle, you could do. 

No comments:

Post a Comment