Reputation: 143
When I am importing one js file into another js, normally I am using following syntax.
var userControllerObj = require("../controller/userController"),
userController = new userControllerObj.UserGatewayController();
My doubt is, can I use let or const instead of var. I know that, these 3 data types have different scope. Still am having confusing between const and let.Some one please explain it.
Upvotes: 0
Views: 1971
Reputation:
Yes you can use any of them for import .
var :
With var, the variables you create are function scoped.
let :
The main difference between var and let is that let is block scoped, instead of function scoped.
const :
The difference between let and const is not too big.
In fact, all the differences between var and let are also true for var and const.
In other words, let and const is almost the same. They are both block scoped and work the same way.
The only thing that makes const different is that is a constant.
So you can use any of them for import.
Upvotes: 1
Reputation: 434
Ideally you should be using const
if your app is capable of es6. In ideal world you won't be changing the reference of imported modules so no need for let
. While declaring variables always start with const
and if you feel need of reassignment somewhere, then change it to let
.
Note: const
doesn't mean you can't change value, you can't just change the reference.
Upvotes: 2