简体   繁体   中英

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?

Mutability should be opt in, rather than opt out.

Whenever possible make everything const .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM