should i be using var in node js or does it use es6 convention

im new to node and ive been using let and const mostly for declaring variables, but in searching through documentation im reading a lot of references to using var as a variable instead of let, does nodejs use the same variable scoping as vanilla js and the reference documents im reading just outdated?

2 thoughts on “should i be using var in node js or does it use es6 convention”

  1. Yes, both Node and browser run JavaScript in the same fashion, they both adhere to EcmaScript, which specifies the rules of JavaScript.

    There are ways to know exactly which ES6 features are supported, but NodeJS has been supporting let and const since a long time. The only disparity you should probably worry about is ESM vs CommonJS but it doesn’t have anything to do with var/let/const.

    So I’d encourage you to use let and const instead of var when writing NodeJS code.


Leave a Comment