by | Aug 12, 2019 | Software


The following text is meant to be enjoyed through a lens of humor and a bit of sarcasm. As you read, don’t take my writing too seriously and if this is a new subject for you, I’d highly recommend researching the JavaScript var Statement before you continue on.

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

Another thing that we know about var is that variables declared with it are processed at the beginning of the function or script depending on its lexical environment. This means that you can assign the variable a value before you declare it which is a great way to keep your code flexible. This type of behavior is also called hoisting, which I’ve often heard described as physically moving code to the top of it’s scope. However, it’s actually just a bi-product during the creation phase of javascript execution when memory is being allocated.

VAR Is Superior

With all this being said, it’s no wonder why var remains the superior way to declare variables in javascript. Next time you’re thinking about using const and let, don’t forget about var because if you do, there may not be any unintended variable leaks which is what makes your code globally accessible.

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.


Submit a Comment

[BLNDSPT] Headquarters:

1553 Platte Street, Suite 300
Denver, CO 80202

Call Us:

(720) 574 - 9900

[ELEVATION] Headquarters:

1553 Platte Street, Suite 202
Denver, CO 80202