What are variable in javascript

What are Variables in JavaScript?

I’m damn sure you have heard the word variable while getting started in any programming language but do you know what are variables in javascript?

Variable: Variables are just like containers that are used to store some values. Values could be anything like string, number, Boolean, and array.

Now, let’s see how to declare a variable in javascript. To define a variable in javascript we can simply use the keyword var in front of the variable name and we will use the = operator to assign a value to the variable. We’ll also put a semicolon (;) at the end

Here we’ll create a variable called myName and assign a value “Papa Programmer”. So let’s see all this in action.

var myName = "Papa Programmer";

Here, myName is a variable name and Papa Programmer is a value. so we can say that now the string “Papa Prgorammer” is stored in myName.

Now lets see how to print a variable’s value in the console.



What are Variables in JavaScript - papaprogrammer

We can also assign a new value to that same variable name and when we do that, the newly assign value will overwrite the past assigned value.

What are Variables in JavaScript - papaprogrammer

Here you can see we have first give a value “Papa Programmer” to the variable myName and after that we have reassign the value to “New papa Programmer” and now if we print the variable then the output will be “New papa Programmer” because this new value will overwrite the previous value.

There are some other keywords like const and let which we can use instead of a var while defining the variable name. but there is a difference in these all three which we’ll cover later.

Next we’ll cover different data types of JavaScript.

You can try some little JavaScript code on this site.

Related Post: Getting Started With JavaScript In Visual Studio Code

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like