Jump to content

Var vs. Let


Don E
 Share

Recommended Posts

Hello, long time no post, but always reading the forums. 

I was wondering opinions on what is the good standard/practice or recommendation when it comes to using var or let when declaring variables?

I know there are instances when to use let and/or var as shown here for example: https://www.w3schools.com/js/js_let.asp but when browsing around looking at JavaScript code these days, I'm noticing more code with let instead of var even if it's a simple example with a few or so lines of code.

I know both var and let have their place when declaring variables, but generally, what would be more of a good standard/practice-recommendation? Thanks.

Link to comment
Share on other sites

People mainly use the let keyword because in most cases you won't need to use a variable outside of the block it was declared in. Though this doesn't mean there's any problem with using the var keyword. Understanding both of them and choosing the right one for the job is my recommendation.

 

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...