JavaScript variables
What you will learn here about javascript variables
- What is variable
- How to define variable in javascript
- How to call variable in javascript
What is variable
We all know in every programming language data is stored in some memory location. So variable is nothing but the name corresponding to the memory location.
How to define variable in javascript
In javascript variable is defined using keyword var. The general syntax for defining variable in javascript is given below.
Syntax:
var variable_name=value
<script>
//here msg is variable name and “Hello World” is assigned value
var msg=”Hello World”;
console.log(msg);
</script>
//here msg is variable name and “Hello World” is assigned value
var msg=”Hello World”;
console.log(msg);
</script>
How to call variable in javascript
Like other programming languages, variables in javascript are called by using variable name only.