Learn the 2 new keywords that ES6 brings for declaring variables: let & const, when and why to use them instead of the old var keyword.
The variable is a fundamental concept that any developer should know.
var are the statements you can declarate variable.
I’m going to describe each variable type around the declaration, initialization, value access, and assignment. Each of the 3 types (
var) create variables that behave differently exactly in these 4 steps.
This post isn’t quite beginner friendly, but rather useful to solidify your knowledge of variables and their behavior.
Let’s get started.
First, let’s understand what a variable is.
The variable has a name, which stricter is called identifier. Examples of identifiers are
The syntax of an identifier is pretty simple:
An identifier can contain letters, digits
0..9, and special symbols
_. An identifier cannot start with a digit
Examples of valid identifiers are
Now things has changed and two new keywords have been introduced to meet the developers needs who felt the old one way solution very tight for the modern web app requirements.
In this article I will try to explain you in the simplest way possible, the differences between var, let and const type variables.
I think the best way to do this is to try to extrapolate the essence of their nature by describing them in few words followed by examples which gives you the confirmation and consolidation of what you learned in the theory.
When ECMAScript 6 (also known as ECMAScript 2015) was released a collection of new APIs, programming patterns and language changes became a standard. Since ES6 started gaining browser and nodejs support developers are wondering if they should stop using the traditional var to declare variables.
ES6 introduced two new ways to declare variables, let and const.
var - has function level scoping and can change the value reference
let - has block level scoping and can change the value reference
const - has block level scoping but cannot change the value reference
Both provide better block scoping that var. const differs from let because the immediate value cannot be changed once it is declared.
We will distinguish between the three with the following features:
Official Website: https://techstackmedia.com
Become a patron to learn more: https://www.patreon.com/techstackmedia
Techstack Media is in partnership with Skillshare: http://bit.ly/tsm-skillshare
Learn anything and get the required skill you need to kickstart a long-lasting career.
Website Request: firstname.lastname@example.org
✅ Facebook: https://facebook.com/techstackmedia
✅ Twitter: https://twitter.com/techstackmedia
✅ Instagram: https://instagram.com/techstackmedia
✅ LinkedIn: https://linkedin.com/in/techstackmedia