Page 72 - Trackpad_V5_Book 8
P. 72

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.
            If you want to perform some mathematical calculations, then we need to convert the value into an

            integer by using the parseInt( ) method. We can use the parseInt( ) method in the following way:

            var num = parseInt(prompt("Enter first number: "));
            The document.write( ) method is used to display output on the web page.

            For example:

            document.write("Hello from JavaScript");
            The preceding statement, will display the message "Hello from JavaScript" on the web page. Let
            us  create a web page to calculate the sum of two numbers in JavaScript.



             70   Pro (Ver. 5.0)-VIII
   67   68   69   70   71   72   73   74   75   76   77