Javascript misc

Switch-case

The following flow chart explains a switch-case statement works: x
Events
JavaScript's interaction with HTML is handled through events that occur when the user or the browser manipulates a page. Events:
When a page loads, when a user clicks a button, pressing any key, closing a window, resizing a window, etc.
onclick Event Type This is the most frequently used event type which occurs when a user clicks the left button of his mouse.
Cookies
Your server sends some data to the visitor's browser in the form of a cookie. The browser may accept the cookie. If it does, it is stored as a plain text record on the visitor's hard drive. Now, when the visitor arrives at another page on your site, the browser sends the same cookie to the server for retrieval. Once retrieved, your server knows/remembers what was stored earlier. Cookies are a plain text data record of 5 variable-length fields: Expires: The date the cookie will expire. If this is blank, the cookie will expire when the visitor quits the browser. Domain: The domain name of your site. Path: The path to the directory or web page that set the cookie. This may be blank if you want to retrieve the cookie from any directory or page. Secure: If this field contains the word "secure", then the cookie may only be retrieved with a secure server. If this field is blank, no such restriction exists. Name=Value: Cookies are set and retrieved in the form of key-value pairs. JavaScript can manipulate cookies using the cookie property of the Document object. JavaScript can read, create, modify, and delete the cookies that apply to the current web page. The simplest way to create a cookie is to assign a string value to the document.cookie object, which looks like this. document.cookie = "key1=value1;key2=value2;expires=date";
Page Redirection
You can refresh a web page using JavaScript location.reload method. This code can be called automatically upon an event or simply when the user clicks on a link. If you want to refresh a web page using a mouse click, then you can use the following code: <a href="javascript:location.reload(true)" >Refresh Page </a>
Dialog box
Alert Dialog Box
An alert dialog box is mostly used to give a warning message to the users Confirmation Dialog Box A confirmation dialog box is mostly used to take user's consent on any option. It displays a dialog box with two buttons: OK and Cancel.
Prompt Dialog Box
The prompt dialog box is very useful when you want to pop-up a text box to get user input. Thus, it enables you to interact with the user. The user needs to fill in the field and then click OK.
Void
Void is an important keyword in JavaScript which can be used as a unary operator that appears before its single operand, which may be of any type. This operator specifies an expression to be evaluated without returning a value.
Page printing
Many times you would like to place a button on your webpage to print the content of that web page via an actual printer. JavaScript helps you to implement this functionality using the print function of window object. < input type="button" value="Print" onclick="window.print()" / >
Objects
Objects are composed of attributes. If an attribute contains a function, it is considered to be a method of the object, otherwise the attribute is considered a property.
Number
The Number object represents numerical date, either integers or floating-point numbers. In general, you do not need to worry about Number objects because the browser automatically converts number literals to instances of the number class.
Boolean
The Boolean object represents two values, either "true" or "false".
String
The String object lets you work with a series of characters; it wraps Javascript's string primitive data type with a number of helper methods.
Array
The Array object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.
Date
The Date object is a datatype built into the JavaScript language. Date objects are created with the new Date().
Math
The math object provides you properties and methods for mathematical constants and functions. Unlike other global objects, Math is not a constructor. All the properties and methods of Math are static and can be called by using Math as an object without creating it. Thus, you refer to the constant pi as Math.PI and you call the sine function as Math.sin(x), where x is the method's argument.
Regular expression
A regular expression is an object that describes a pattern of characters. The JavaScript RegExp class represents regular expressions, and both String and RegExp define methods that use regular expressions to perform powerful pattern-matching and search-and-replace functions on text.
Document object
Every web page resides inside a browser window which can be considered as an object. A Document object represents the HTML document that is displayed in that window. The Document object has various properties that refer to other objects which allow access to and modification of document content.
up