You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While looking through the node.js source code, I have found quite a few var declarations. In the same files I have also found let declarations. let declarations are almost always considered better, and can always be used in place of var declarations. I was thinking about fixing this and creating a PR but wanted to know if there was a specific reason for using var sometimes and let other times. Scope could be a reason, but could be transformed like this:
if(/*...*/){varfoo='bar';}//is the same asletfoo;if(/*...*/){foo='bar';}
The text was updated successfully, but these errors were encountered:
The var is a variable global than when you try declaring a new variable with the same name will throw an error. Just the variable of the type let respect a scope.
Most of the files in question were written before let and const existed. Changing them en masse to let and const would be considerable churn which risks the introduction of subtle bugs, all for no benefit to the end user.
Many people have opened pull requests to do this and we always close them. Instead, we migrate slowly over time when nearby code is being modified for other reasons. I'm not a fan of that approach either, to be honest, but it has been the sense of the maintainers for a long time that that is the best way to handle this.
An additional reason that we did not convert to let previously is that there were situations where let was significantly less performant than var. I do not believe that is the case anymore, although the potential that it could still be lurking might be another reason some maintainers or reluctant to do this.
Speaking personally, I'm not strongly opposed to doing this, but I'm also not enthused.
Hope this answers your question. I'm going to close this, although you and anyone else should feel free to continue to comment and/or re-open it if this answer does not suffice.
While looking through the node.js source code, I have found quite a few
var
declarations. In the same files I have also foundlet
declarations.let
declarations are almost always considered better, and can always be used in place ofvar
declarations. I was thinking about fixing this and creating a PR but wanted to know if there was a specific reason for usingvar
sometimes andlet
other times. Scope could be a reason, but could be transformed like this:The text was updated successfully, but these errors were encountered: