Page 147 - ComputerGenius_V2.1_Class8
P. 147

Variables


                 A variable is a name of storage location. It stores a value that can be modified later. JavaScript is
                 a loosely typed language which means it does not require a data type to be declared before using it.
                 Syntax to declare a variable in JavaScript is:

                 var <variable name> = <value>;

                 where var is a keyword, <variable name> is a valid name for the variable and <value> is the value
                 that you want to assign to the variable.

                 For example:

                 var age = 16;
                 var name = "A"

                 We can declare multiple variables in the same line in the following way:
                 var v1 = 1, v2 = 'Delhi', v3;
                 Variable Naming Conventions


                 Some of the naming conventions that need to be followed while declaring variables in JavaScript are:

                    Variable names are case-sensitive which means that the variable name ‘AGE’ is different from ‘age’.

                    A variable name must not start with digits 0–9.

                    Variable names can contain letters, digits, or the symbols $ and _.

                    A variable name cannot be a reserved keyword.
                 Operators


                 An operator is a symbol that is used to perform calculations on values or variables. The variables
                 or values on which the operator performs calculation are called operands. Some of the examples of
                 operators are + (Addition), - (Subtraction), * (Multiplication), / (Division), etc.

                 Expressions


                 An  expression is a  unit  of code  that  is evaluated to  a  value.  It is a  combination  of values  and
                 operators. For example,

                 a = b + c;
                 Comments


                 A comment is used to add notes in your code or to disable sections of code without deleting them.
                 Comments are ignored by the JavaScript interpreter. There are two types of comments in JavaScript:
                 single line and multi line. Single line comments are added by using // and multi line comments are
                 added by using /* and */.





                                                                                   Introduction to JavaScript  145
   142   143   144   145   146   147   148   149   150   151   152