The most accessible way to use data in a script is to first assign it to a variable. It’s generally easier to suppose a variable as a handbasket of information. How long a variable retains information depends on several factors. Still, as soon as the web runner clears the window, all known variables are incontinently discarded.
That statement lets the cybersurfer know that you can use that variable later to hold data or to alter any of the data in that variable.
To assign a value to a variable, use one of the assignment drivers. The most common done by far is the equal sign.However, I use that assignment driver in the same statement as the var keyword similar as If I want to assign a value to the myAge variable at the same time I declare it as:
On the other hand, if I declare a variable in one statement and indeed want to assign a value to it, the sequence of statements will be:
After defining a constant, its value can not be reassigned. trying to do so will raise a TypeError,illustration:
pi = 3.15;// TypeError Assignment to const variable.
It’s recommended to use constants whenever there are values that shouldn’t be changed.
Constants make your law easier to read and help crimes that can do when variable values change suddenly. still, the constant value can not be changed, but it’s parcels and rudiments can still be changed, If the value is an object or array,illustration: