on Leave a Comment

JavaScript Variables

As other programming languages, JavaScript also supports data types and variables. Variables are piece of memory blocks in which we can store data (values). And data types decides what type of data can be stored in variables and what operations on variable can be performed.

JavaScript supports following data types:

Number, e.g. 100, 105.5, 10.0 etc.
String, e.g. 'abc', "xyz" etc.
Boolean, e.g. true and false 
Null and Undefined
Object (composite data type)

JavaScript represents numbers as 64-bit floating-point format defined by the IEEE 754 standard.

Example of JavaScript Variable

var keyword is used to declare variables in JavaScript

<script type="text/javascript">
      var a = 10;
      var b = 20;
      var c = a + b;
</script>

In above example, we define three variable using var keyword namely a, b and c. Variables a and b stores 10 and 20 respectively. And sum of a and b is assigned to variable c.

JavaScript Identifiers

All names are Identifiers. A variable must have unique name.

- Reserved words cannot be used as a variables name.
- Variables name should not start with a number like 0, 1, 2.
- Variable name should start with a alphabets or underscore like abc, _abc.
- All variable names are case sensitive.








0 comments:

Post a Comment