In the previous Javascript post I outlined what variables were, and how to declare them using 'var'. However, var is not the best method to use in 2020.
As of ECMAscript 2015, a javascript update also known as ES6, there are new ways to declare variables. Introducing......... let and const!!!!
For now, 'let' is essentially the same as 'var'. Later in this course we will discuss some small differences, but for now let's assume that they're the same thing, and that it's better to always use let instead of var because it's newer, and likely to stick around for longer.
But what about const? Well const is essentially the same thing as 'let', except that const variables can never be changed. If you do:
const name = 5;
then the variable 'name' will never stop being 5. Trying to change it will result in an error in the console. Const variables can also never be undefined.
CHALLENGE: Assign some variables with let, var and const and try to log them to the console. Then, read the next Javascript post on how to change variables and do that challenge.
If you have any questions, let me know in the comments section.
- Noah
As of ECMAscript 2015, a javascript update also known as ES6, there are new ways to declare variables. Introducing......... let and const!!!!
For now, 'let' is essentially the same as 'var'. Later in this course we will discuss some small differences, but for now let's assume that they're the same thing, and that it's better to always use let instead of var because it's newer, and likely to stick around for longer.
But what about const? Well const is essentially the same thing as 'let', except that const variables can never be changed. If you do:
const name = 5;
then the variable 'name' will never stop being 5. Trying to change it will result in an error in the console. Const variables can also never be undefined.
CHALLENGE: Assign some variables with let, var and const and try to log them to the console. Then, read the next Javascript post on how to change variables and do that challenge.
If you have any questions, let me know in the comments section.
- Noah
Comments
Post a Comment