Declaring Variables in Javascript
JavaScript implement loosely types technique for declaring variable i.e. variable can take any form of data String or Number. A variable is responsible for holding the data in the computer memory. To access this data from the memory JavaScript refer to the variable name.
Syntax:
var variable_name;Example - Assigning Numeric value to variable
<script type="text/javascript"> var myVariable = 5; //Assign number 5 to myVariable </script>
Example - Assigning String value to variable
<script type="text/javascript"> var myVariable = "this is a string"; //Assign string "this is a string" to myVariable </script>
To perform mathematics operations on the variables Arithmetic Operators are used. Arithmetic Operators used are Addition(+), Substraction(-), Multiplication(*), Division(/). Apart from arithmetic operator there are special operator like Modulus(%), Incremental(++) and Decremental Operator(–). The other sets of operator getting used in JavaScript are the Boolean Operator viz AND(&&), OR(||)and NOT(!) operator.
Keywords in Javascript:
These are special words reserved only for the JavaScript engine. These words has special meaning for the JavaScript parser and so these words cannot be used as a variable in JavaScript. If you try to assign this keywords as variables JavaScript will start throwing errors.
Similar Posts
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.


Comments
No comments yet.
Leave a comment