Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to require node modules var or const?

When we are requiring node modules such as express or bodyParser we will use the var keyword to create a variable and assign the module. Can't we use const to declare such modules? That is, instead of this

var express = require('express');
var app = express();

should we do this

const express = require('express');
const app = express();

What is the best way? And why is that?

like image 887
Dhanuka Perera Avatar asked Sep 03 '25 02:09

Dhanuka Perera


1 Answers

Mutability should be opt in, rather than opt out.

Whenever possible make everything const.

like image 127
arboreal84 Avatar answered Sep 04 '25 22:09

arboreal84