Two Dimensional Arrays - Computer Programs Via Web - Lecture Notes | CMSC 122, Study notes of Computer Science

Material Type: Notes; Professor: Padua-Perez; Class: INTRO COMP PROG VIA WEB; Subject: Computer Science; University: University of Maryland; Term: Spring 2009;

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-hcb
koofers-user-hcb 🇺🇸

8 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Announcements
Check class announcements daily
You must implement programming projects by yourself
1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Two Dimensional Arrays - Computer Programs Via Web - Lecture Notes | CMSC 122 and more Study notes Computer Science in PDF only on Docsity!

Announcements

 Check class announcements daily

 You must implement programming projects by yourself

Two-Dimensional Arrays

 JavaScript does not support actual two-dimensional arrays

 You can simulate two-dimensional arrays by using arrays of arrays

 About two-dimensional arrays

 You can pass them and return them from functions like one-dimensional arrays  Any modifications in the function will be permanent  You can have ragged arrays

 Nested loops (in particular for loops) are used with

two-dimensional arrays

Example: TwoDimensionalArrays.html

Example: Let’s define a two-dimensional array of strings

Objects

 You use the. (period) operator to access an object’s properties  .  A property value can be any data type we have seen including objects  You can create your own objects by either: var myObj = {}; var myOtherObj = new Object();  You can create properties by assigning a value to it (we do not use var) myObj.created = “Monday”;  You can update the property by assigning a new value  You can delete a property with the delete operator delete myObj.created;  You can check for the existence of a property using the “in” operator  Example: ObjectEx.java

for/in

 General form for (propertyName in object) statement  Can be used to display the properties of an object  for/in does not specify the order in which properties of an object are visited  Example: ObjectEx.java  The for/in does not loop through all the possible properties as some properties are considered non-enumerable  User-defined properties are enumerable

Global Object

Global object  created by JavaScript interpreter when it starts up  Interpreter initializes the Global object with predefined values and functions. For example, parseInt, Infinity, etc.  Top-level code  JavaScript code that does not belong to a function  Global variables  variables in top-level code  Global variables are properties of the Global object. When you define a variable outside any function you are defining a global variable (a property of the global object)  You should avoid using global variables in your code  In client-side JavaScript the Window object (window) represents the global object for all JavaScript code present in the browser window  You can use the keyword this to refer to the Global object  Example: GlobalObject.html

SESSIONS

 Session - time period during which a person views a number of different web pages in a browser and then quit  What would you like  To keep track of information throughout the session  For example, keeping track of color preferences, usernames, data selection, etc.  What is the problem?  http (the protocol that makes possible the communication between browsers and web servers) is stateless (it has no memory)  Stateless  every page request is independent  One Possible Solution  Cookies

Cookies

 Each cookie consists of name, value, expiration date, host, and path information  This is how the cookie information may look like when sent by the server in the http header Set-Cookie: automobile=nelyota; path=/; domain=notRealCars.com  If no expiration date is set for a cookie, the cookie expires when the user's session expires (i.e., when the user closes the browser)  If the user accesses any page matching the path and domain of the cookie, the browser will resend the cookie to the server  Let’s see cookies in our browser

Setting/Reading Cookies

 Setting cookies

 We can set a cookie by using document.cookie

document.cookie = “school=UMCP”;

document.cookie = “mascot=terp”;

 Example: setCookie.html

 Reading cookies

 document.cookie has a string with all the cookies

 You must extract from the string each cookie

 Cookies are separated by ;

 Example: readCookie.html