Page 19 - LoudOffice_Guide-to-HTML_Part-II_Advanced.PDF
P. 19

Type
               The data assigned to a variable may consist of any sort of data. However, JavaScript
               considers data to fall into several possible types. Depending on the type of data, certain
               operations may or may not be able to be performed on the values. For example, you cannot
               arithmetically multiply two string values. Variables can be these types:

               Numbers           3 or 7.987, Integer and floating-point numbers.
               Booleans          True or False. The possible values for Boolean variables are true and false.
                                 In a comparison, any expression that evaluates to 0 is taken to be false,
                                 while any statement that evaluates to a number other than 0 is taken to
                                 be true.
               Strings           "Hello World !" Strings are delineated by single or double quotation marks.
                                 (Use single quotes to type strings that contain quotation marks.)
               Objects           An object is a “package” of data; a collection of variables that are all
                                 classed under a single name.
               Null              Not the same as zero - no value at all. A null value is one that has no
                                 value and means nothing.
               Undefined         A value that is undefined is a value held by a variable after it has been
                                 created, but before a value has been assigned to it.

               JavaScript is a loosely typed language --    you do not have to specify the data type of a
               variable when you declare it, and data types are converted automatically as needed during
               script execution. By and large, you may simply assign any type of data to any variable. The
               only time data typing matters is when you need to perform operations on the data. Certain
               operators behave differently depending on the type of data being deal with. For example,
               consider the + operator:

                                          " s h o t "  yields  " J u m p s h o t "  (string concatenation)
                             " J u m p "  +
                                                 1 0   yields  1 5  (arithmetic sum)
                                           5  +


               Operators
               Operators take one or more variables or values (operands) and return a new value; e.g. the
               '+' operator can add two numbers to produce a third. You use operators in expressions to
               relate values, whether to perform arithmetic or compare quantities. Operators are divided
               into several classes depending on the relation they perform.

               Arithmetic or Computational
               Arithmetic operators take numerical values (either literals or variables) as their operands
               and return a single numerical value. The standard arithmetic operators are:

                           +    Addition  (Can also be used to concatenate strings)
                           -    Subtraction
                           *    Multiplication
                           /    Division
                          %     Modulus: the remainder after division;
                                e.g. 10 % 3 yields 1.



               LoudOffice.com Guide to HTML – Part II                                               Page 19
   14   15   16   17   18   19   20   21   22   23   24