JavaScript Variables
Learn about the different types of variables in JavaScript.
We'll cover the following...
By the end of this lesson, we’ll be able to understand the differences between var, let, and const and how to use them correctly.
In JavaScript, variables can be declared with var, let, or const.
Note: The
letandconstkeywords were introduced in ES6 and are the preferred variable declaration methods for this course.
Variable update
The var variables can be updated and redeclared within its scope.
Let’s take a look at the code below. What will be logged to the console? Why?
Press + to interact
Javascript (babel-node)
var color = "red";var color = "yellow";console.log(color);
The value yellow is logged because var variables can be updated and redeclared ...
Ask