VAR BEST = TRUE;
In an ever-changing world filled with constant advancements and life-altering discoveries, are there any constants left? Am I bound to a world of never-ending ambiguity, or is there still a rock out there somewhere that can hold me down? With the introduction of let and const in ECMAScript 6 (ES6), an old friend still has a place in the hearts of many.
The Humble VAR
The VAR keyword needs no introduction. It’s been there from the beginning and it will stay till the end as the undefeated — objectively — best variable declarator.
You may have read somewhere online how it’s typically safe to declare a variable using the const keyword and then switch to let down the road if necessary. This isn’t bad advice, however, if you know that const and let basically behave the same [ besides mutability] you can save yourself some time.
But wait, “where does this leave var?“, you may be asking.
VAR Has No Block Scope
Let’s start with what we know about it besides the fact that it’s the best. Unlike const and let, var has no block scope. This effects where the variable is available in the code. Without a block scope, variables are either function-wide or global.
Sounds pretty cool, right?
This means that there are less restrictions about where you can access the variable lexically in your code.
Flexible Coding With VAR
VAR Is Superior
The talented engineers at Blndspt code in every language and have a great sense of humor, as you can glean from the above article! Check out what else we do and get in touch about your next digital project.
1553 Platte Street, Suite 300
Denver, CO 80202
(720) 574 - 9900
1553 Platte Street, Suite 202
Denver, CO 80202