You can change the value contained inside a variable using the syntax given below:
var x = 10; // declaration & initialization x = 15; // updation console.log(x);
The above code snippet prints the output as 15. Here, you are assigning a different value to the variable x declared & initialized earlier.
The = acts as an assignment operator to assign the contents (literal/another variable) on the right-hand side to the container (variable) on the left-hand side.
In the next video, you'll learn about what are the rules for naming a variable in JavaScript.
So, you have learnt that the name that you give to a variable is called an identifier and you have also learned the naming conventions. Let's now summarise the conventions for naming the identifiers in JavaScript.
There’s another rule you need to know for identifiers. There are some reserved keywords in JavaScript. These keywords are used by Javascript in some other contexts. One such keyword is var. Below is a list of all the reserved keywords in JavaScript.
You cannot use the reserved words or keywords in JavaScript for naming identifiers.
In the next video, you'll learn what comments are and how you can write them in JavaScript. You will also look at why they are used.
In the last video, you learned about comments. Comments are critical as they are often helpful in explaining what a particular line or chunk of code does. If you noticed, there were comments written in the coding console questions to help you understand what steps you need to follow and these comments were not a part of the final output. So, now you know how comments are can be of great use.