Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Node.js commonly use 'var' instead of 'let'?

Basically every tutorial I’ve watched on Node.js, and even the express generator has all variables declared using var instead of let? From what I’ve learned in Javascript.info let should be the standard unless for very niche cases.

like image 956
Brandon Avatar asked Sep 16 '19 06:09

Brandon


1 Answers

It is because the Node.JS code is written in ES5 which does not support the use of let and const. If you still wish to write your code in ES6, you need to use something called Babel which will help Node.JS to convert the ES6 code into ES5. But you can definitely use let and const in Node. I hope the answer helps.

Please refer to the below link for an in-depth explanation. https://dev.to/dhruv/writing-es6-in-your-nodejs-applications-33jk

like image 140
Sunny Parekh Avatar answered Sep 27 '22 22:09

Sunny Parekh