Page 203 - Web Applications (803) Class 12
P. 203

for (i=0;i<fruits.length;i++)
                    document.write(fruits[i]+"<br>");
                    </script>

                    </font>
                    </body>
                    </html>
                 Output of the preceding program is as follows:















                 In the above example, the for loop uses the counter ‘i’ as index value to access each element.
                 If we try accessing a non-existent array index, we get undefined
                 Example:

                    typeof fruits[20]
                 Output: undefined

                   3.11 OBJECTS IN JAVASCRIPT

                 In JavaScript, almost everything is an object with the exception of six things: null, undefined, strings, numbers,
                 Booleans, and symbols. These are known as primitive types. An object is anything that isn’t a primitive value.
                 This  covers  constructors,  functions,  and  arrays. Yes!  we  will  see  later  in  the  chapter,  objects  also  include
                 functions and arrays.
                 In terms of concept, objects are the same across all programming languages. They represent entities from
                 the outside world that we want to express in our programs through properties, and methods. For instance,
                 your object will include properties like name, age, address, id, etc., as well as methods like updateAddress,
                 updateName, etc., if it is a student.

                 Consider an object in JavaScript as a list of items, each of which is a property or method that is kept as a key-
                 value pair in memory. For example:
                    const student = {Name : "Uma", age : 15, Address  : "Green Park" };





                              Object              Key                     Value


                 In JavaScript, the named values are called properties.
                                               Property                             Value
                                   Name                               Uma
                                   Age                                15
                                   Address                            Green Park


                                                                                          Web Scripting—JavaScript   201
   198   199   200   201   202   203   204   205   206   207   208