Page 50 - 2611_SmartGPT Pro V(5.0) C-8
P. 50

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: ");
                  When the preceding statement is executed, a prompt box will appear in the web browser asking
                  to input the age. By default, the input taken by the prompt( ) method is considered as a string in
                  JavaScript.




                   48   Computer Science (V5.0)-VIII
   45   46   47   48   49   50   51   52   53   54   55