The Workshop


Declaring Variables in JavaScript

This weekend I had the privilege of attending Zac Gordon’s “Introduction to JavaScript” class at WordCamp DC. I found the session to be both fast-paced and highly informative. One interesting concept that stuck out to me is how JavaScript handles variables.

When implementing JavaScript, there are three ways to declare variables: var, let and const. Var is the old, all-encompassing way to declare a variable. A variable declared using var can be reassigned if necessary, and it can be used anywhere throughout a function.

Let and const refer to more specific instances of declaring JavaScript variables. Let refers to a variable that may be reassigned at some point, and will only be used in the specific segment of code where it was declared. Conversely, const refers to a variable that cannot be reassigned.

At this point I have only used var to declare JavaScript variables, so it make take some time to wrap my head around this concept. However, I am sure that this information will  come in handy at some point in the future.

Leave a Reply