You know what is a variable, don’t you? We’ve learned it from our primary classes also. We have solved some problem using this variable concept. So let’s remember it.
X = laptop (I created a variable as X, so X is equal to Laptop)
I can live without my X (Yeah, I just assigned X variable to a sentence. It means “I can’t live without my laptop“)
We can assign anything to easy and fast up our work with this concept. Maybe it’s a text, numerous thing, image, audio or whatever it is, we can make a variable and use the variable everywhere we need to place.
var x = 21;
OK, you made a variable, here you need to remember the semicolon is needed when you’re making a variable. Just remember it. Now let’s print the variable we created in the browser.
After typing the second line you will get your output as 21.
OK, Now let’s add some text to the variable.
document.write(‘I am ‘ + x + ‘ years old’);
The benefit of making variables is, if you change a variable value one time, all the values assigned by the variable will be changed one time. and another most important thing is variable are case sensitive, it means capital X is not equal to simple x. if you do it you will get nothing. And another thing is you need to start your variable name with a letter or an underscore (_). you cannot use & or percentage signs or anything like that. In addition, other letters can be only letters, numbers, and underscore. Just remember it and never do this mistake. and lastly, your variables can’t start with a number. Finally, if you follow these simple rules, you’re good to go.