Learning Javascript Variables

Learning Javascript Variables
Variable means anything that can vary or change. here In JavaScript language a variable stores the data value that can be changed any time in future.

Lets understand in coding language.

<script>
document.write("Welcome to Eyeshiv");
document.write("Welcome to Eyeshiv");
document.write("Welcome to Eyeshiv");
</script>

here we are Writing “Welcome to eyeshiv Technologies” in our code 100 time. suppose we want some changes on our content we want to add Technologies wold here like “Welcome to Eyeshiv Technologies”

So what we have to do we have to add 100 time in various space of our code.

To resolve this problem her we use variable

like

<script>
X = "Welcome to Eyeshiv"
document.write(x);
document.write(x);
document.write(x);
</script>

Here we don’t need to write large content like “Welcome to Eyeshiv”  every time.

Just write one time call the variable. This way we make is easy.

Types of Variable

There are Three way to write Variable

  1. var
  2. let
  3. Const (constant)

Variable var

With variable we can declare and assign or override the value multiple times.

<script>
var x = "Hell Welcome to Eyeshiv Technologies"; /
var x= "Hello welcome";

x = "400";
x = "5000";
document.write(x);
</script>

output will be  5000

 

Let

With let variable we can override the value but we can’t declare the the value again

<script>
let x="How are you Yatharth"
let x = "333" //it will get error
x   =""
Document.write("x")
</script>

 

Const (constant)

Once we declare the value we can’t declare again and can’t override

<script>
const firstname = "Hello how are you?";

document.write(firstname);
</script>