Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Does node.js support the 'let' statement?

Does node.js support the 'let' statement?


Does node.js support a let statement something like what's described on MDN??

var x = 8,
    y = 12;

let ( x = 5, y = 10) {
    return x + y;
} //15

If not, is there a way to duplicate the functionality with a self-executing anonymous function or something?

And/or is there another js environment that

  1. has let and and
  2. has a REPL, as node does? Rhino?


This question was asked quite a while ago. As of now, late 2015, the answer is "Yes, yes it does". Harmony features were included by default in io.js 3.3, and have been recently brought back to node.js with the 4.x release.

Problem courtesy of: ben author


I don’t think Node supports let, but you can do this:

var a = 5;

(function () {
  var a = 6;
  console.log(a); // => 6

console.log(a); // => 5
Solution courtesy of: Todd Yandell


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Does node.js support the 'let' statement?


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription