JavaScript Learning Notes (ii)

Source: Internet
Author: User

= = = Scope ======var color = "Blue";/*function ChangeColor () {if (color== "blue") {color = "red";} Else{color= "Yellow";}} ChangeColor (); alert ("Color is now" +color);//Output Color is now Red*///====object type ======//One, there are two ways to create an object instance. The first is the use of the new operator followed by the object constructor/*var person = new Object ();p erson.name = "Yoyo";p erson.age = 24;alert (json.stringify (person ); *///the second is to use the object literal variable notation/*var person = {name: ' YY ', Age:29};*///alert (json.stringify (person)),//alert (person.name);// Alert (person["name"]);//==== object literal ======/*function displayinfo (args) {var output = ""; if (typeof args.name = = "string") { Output + = "Name:" + args.name + "\ n";} if (typeof args.age== "number") {output+= "Age:" +args.age+ "\ n";} alert (output);} DisplayInfo ({name: "YY", age:24}); DisplayInfo ({name: "Yoyo"}), *///========array=========var colors = ["Red", "Blue", "Green"];//alert (colors[3]); Colors[2]= "BLACK"; colors[4]= "Brown"; When larger than the array length, it is automatically added to the array, length plus 1.//alert (colors),//if (colors instanceof Array) {//instanceof array to determine if an object is not an array//alert (" Colors is an Array. "); /}//======1.arrayobject.join (separator) ====alert (Colors.join ("-")); If an item is null or undefined, the value is represented as an empty string in the results returned by the join (), tolocalestring (), toString (), and valueof () methods.
= = = Stack method ====var colors = new Array (), var count = Colors.push ("Red", "green");//alert (count); ->2//alert (colors); Red,greencount = Colors.push ("BLACK"); alert (colors.length); ->3alert (count); ->3var item = Colors.pop (); alert (item); ->blackalert (colors.length); ->2

  

JavaScript Learning Notes (ii)

Related Article

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.