Page 144 - DCAP408_WEB_PROGRAMMING
P. 144

Web Programming




                    Notes          false. When using numeric comparison and equality operators, the value true evaluates to 1 and
                                   false evaluates to 0.
                                          answer1  =  true;
                                                 or
                                          if  (answer2  ==  false)  {  do  something;  }

                                   5.2.2 Composite Data Types

                                   We mentioned that there are two types of data: primitive and composite. The   primitive types:
                                   numbers, strings and Booleans—each storing a single value. Composite data types, also called
                                   complex types, consist of more than one component. Objects, arrays, and functions, covered
                                   later in this book, all contain a collection of components.
                                      Objects contain properties and methods
                                       Arrays contain a sequential list of elements

                                       Functions contain a collection of statements

                                   Self Assessment

                                   Fill in the blanks:
                                   4.  ……………….. specify what kind of data, such as numbers and characters, can be stored
                                       and manipulated within a program.

                                   5.  String literals are rows of characters enclosed in either ……………….. quotes.
                                   6.  The process of joining strings together is called ………………..
                                   7.  Composite data types, also called ……………….. types, consist of more than one component.

                                   5.3 Variables


                                   A variable’s purpose is to store information so that it can be used later. A variable is a symbolic
                                   name that represents some data that you set. To think of a variable name in real world terms,
                                   picture that the name is a grocery bag and the data it represents are the groceries. The name
                                   wraps up the data so you can move it around a lot easier, but the name is not the data!
                                   When using a variable for the first time it is not necessary to use “var” before the variable name,
                                   but it is a good programming practice to make it crystal clear when a variable is being used for
                                   the first time in the program. Here in the example VarExample.html we are showing how the
                                   same variable can take on different values throughout a script.


                                          Example: Illustrating variables in java script
                                          <html>
                                          <body>
                                          <script  type=”text/JavaScript”>
                                          <!—
                                   var  linebreak  =  “<br  />”
                                   var  my_var  =  “Hello  World!”
                                   document.write(my_var)



          138                               LOVELY PROFESSIONAL UNIVERSITY
   139   140   141   142   143   144   145   146   147   148   149