Javascript BASICS (unfinished)

Source: Internet
Author: User

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">

<Head>

<Title> </title>

</Head>

<Body>

<SCRIPT type = "text/JavaScript">

/*

VaR X;

If (x = NULL ){

Alert ("null ");

}

If (typeof (x) = "undefined "){

Alert ('undefined ');

}

If (! X) {alert ('No x ');}

If (x) {} // The variable is initialized, the variable is not empty, or the variable is not 0.

*/

/*

VaR r = add (1, 2 );

Alert (R );

R = add ("hello", "Tom ");

Alert (R );

Function add (I1, I2 ){

Return I1 + I2;

}

*/

/*

// Anonymous Function

VaR F1 = function (I1, I2 ){

Return I1 + I2;

}

Alert (F1 (1, 2 ));

*/

/*

JS object-oriented BASICS (*)

JavaScript does not have the class syntax. It is simulated using the function closure (closure,

*/

/*

Function person (name, age) {// declare a function as a class

This. Name = Name; // dynamically generate the attribute name

This. Age = age;

This. sayhello = function (){

Alert ("Hello, I am" + this. Name + ", I" + this. Age + "years old ");

}

}

VaR p1 = new person ("Tom", 20 );

// Var p1 = person ("Tom", 20 );

P1.sayhello ();

*/

/*

Array object

The array object in Javascript is an array. First, it is a dynamic array, and

Is a super complex such as arrays in C #, arraylist, and hashtable.

*/

/* Var names = new array ();

Names [0] = "Tom ";

Names [1] = "Jerry ";

Names [2] = "Lily ";

Alert (names. Join ("| "));

Names. Reverse (); // reverse the element in the array

Alert (names );

For (VAR I = 0; I <names. length; I ++ ){

Alert (Names [I]);

}

Alert (getmax (names ));

Function getmax (ARR ){

VaR max = arr [0];

For (VAR I = 0; I <arr. length; I ++ ){

If (max <arr [I]) {

Max = arr [I];

}

}

Return Max;

}

*/

/*

Dictionary in JS

Array in JS is a baby, not only an array, but also a dictionary or a stack.

It is used like hashtable and dictionary, and it is as efficient as they are.

*/

/*

VaR pinyins = new array ();

Pinyins ["persons"] = "Ren ";

Pinyins ["Port"] = "Kou ";

Pinyins ["hand"] = "Shou ";

Alert (pinyins ["persons"]);

Alert (pinyins. persons );

For (var k in pinyins ){

Alert (K + ":" + pinyins. K );

};

*/

// Obtain all the members of an object: the object's members appear in the form of object keys

For (VAR e in document ){

Alert (E );

}

</SCRIPT>

</Body>

</Html>

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.