Is there an efficiency difference between const vs var while 'requiring' a module in NodeJS [closed]
I was reading the documentation for https://github.com/rvagg/bl and I noticed that, in the examples, they use const to require a module and this made me wonder: is this a good practice? I mean, to me, this looked as a good idea.
A direct example from the link above is:
const BufferList = require('bl')
var bl = new BufferList()
bl.append(new Buffer('abcd'))
bl.append(new Buffer('efg'))
/*...*/
I also noticed the lack the semicolons in the example but well, that has been discussed elsewhere thoroughly.
The const
makes perfect sense here:
- It documents that the
objectreference is not going to change. - It has block scope (same as
let
) which also makes sense.
Other than that it comes down to personal preference (using var
, let
or const
)