Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 70 - 2612_Digimind
P. 70

    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 calculations 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 between /* and */.
                      For example:

                      // alert("Hello");  Single-line comment
                      /* a = 10;
                          b = 20;                  Multi-line comment

                      */

                                INPUT AND OUTPUT IN JAVASCRIPT

                      JavaScript allows us to take input from the user with the help of the prompt() method. We can
                      use the prompt() method in the following way:

                      var age = prompt("Enter your age: ");

                       68   Premium Edition-VIII

| 65 66 67 68 69 70 71 72 73 74 75 |