Getting Started with JavaScript learning notes---

Source: Internet
Author: User

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---

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.