Both 1.JavaScript statements and JavaScript variables are case-sensitive.
2. Re-declare JavaScript variables
If you re-declare a JavaScript variable, the value of the variable is not lost:
After the following two statements are executed, the value of the variable carname remains "Volvo":
var carname= "Volvo"; var carname;
3.JavaScript has a dynamic type . This means that the same variables can be used for different types:
JavaScript Data type -----string, Number, Boolean, array, object, Null, Undefined
4. Array:(in brackets)
var cars=["Audi", "BMW", "Volvo";
5.JavaScript Object (curly braces)
var person={firstname: "Bill", LastName: "Gates", id:5566};
name=person.lastname;name=person["LastName"];
6. Creating JavaScript Objects
Person=new Object ();p erson.firstname= "Bill";p erson.lastname= "Gates";p erson.age=56;person.eyecolor= "Blue";
7. If you add a number to a string, the result becomes a string
8.Switch
Switch (n) {Case 1: Execute code block 1 break;case 2: Execute code block 2 break;default: N code that executes when different from 1 and 2
9.for/in Cycle
exception
An exception can be a JavaScript string, a number, a logical value, or an object. e.g.
<script>function myFunction () {try { var X=document.getelementbyid ("Demo"). Value; if (x== "") throw "empty"; if (IsNaN (x)) throw "not a number"; if (x>10) throw "too high"; if (x<5) throw "too low"; } catch (Err) { var Y=document.getelementbyid ("mess"); Y.innerhtml= "Error:" + Err + "."; }} </script>
11.e-mail Verification
functionValidate_email (field,alerttxt) { with(field) {apos=value.indexof ("@") Dotpos=value.lastindexof (".")if(apos<1| | Dotpos-apos<2) {alert (alerttxt);return false}Else{return true}}}functionValidate_form (thisform) { with(thisform) {if(Validate_email (email, "Not a valid e-mail address!") ==false) {email.focus ();return false}}}</script>Email:<input type= "text" name= "email" size= "><input type=" Submit "value=" Submit "> </form></body >
Getting Started with JavaScript learning notes---