Page 337 - Webapplication11_C11_Flipbook
P. 337

<SCRIPT>
                   var x = 50;

                   var y = 20;
                   var sum = x + y;
                   document.write("The sum is " + sum);

                   </SCRIPT>
                   </BODY>
                   </HTML>
                 When we view the preceding web page in the web browser, the following output appears:
















                 Declaring Constants
                 A constant is a type of variable whose value cannot be modified while the program is running. Constants in JavaScript
                 are declared using the const type, and the name of the constant is only in uppercase by convention. The JavaScript
                 constant variable is supported by a large number of browsers. Examples are as follows:

                   const PI=3.14
                   const RATE=8.9
                 Keywords

                 A keyword is a reserved word that has a special meaning for the JavaScript interpreter.  These terms are not allowed
                 to be used as variable names.
                 The list of keywords is as follows:


                                    break            else             new             var
                                    case             finally          return          void

                                    catch            for              switch          whie
                                    continue         function         this            with

                                    default          if               throw           delete
                                    in               try              do              instance of

                                    type of          interface        null            undefined


                 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 */.

                                                                                                  JavaScript Part 1  335
   332   333   334   335   336   337   338   339   340   341   342