JavaScript Summary 1

Source: Internet
Author: User

Tag:htm    code    char    line Comment     line     def   cat   case   pop   

JavaScript one, the form of JavaScript storage 1, there is a file 2, nested in the HTML file 3, the general JS code is placed on the bottom of the body tag, even if the JS request does not affect the page display two, javascript declaration variable name = " Alex "declares a global variable var name =" Zidane "declares a local variable, the local variable is also the most commonly used/*xxxxxxxxxxxxxxxfff*/above this is a multiline comment//xxxxfff the following is a single-line comment three,        There are three basic data types for JavaScript data types: Numeric, string, array number type, var age = 19; var age = number (ten) var name = "Alex" var a1 = 12,a2 = 13,a3 = 14 Convert variable number ("123") parseint ("123") convert a string to a number  The word type parsefloat () converts the type of a number to a float print variable, printing the variable's value separately and the variable's type Console.log (age) Console.log (typeof age) Console.log (typeof Name) string type var name = "Alex" Trim: Remove the string space Name.trim () remove the space on either side of the string Name.trimleft () remove the space to the left of the string Name.trimright () Remove the space to the right of the string charAt: Take the value of the string by index Name.charat (0) Displays the first element of the string Name.charat (3) shows the fourth element of the string substring: Gets the substring of the string var name = " ABCDEDFG "name.substring (2,4) Results: cdindexof: Gets the subscript of a character in the string Name.indexof (" F ") Length: Gets the length of the string Name.lengthboolern: Boolean value, 0 is False, 1 is true Boolern (0) Falseboolern (1) True array: the equivalent of the list in Python to create an array of two ways var li = ["A", "B", "C"]var li = Array ("A", "B", "C") Li.push ("D") inserts D into the array li.unshift ("oo"Insert Oo into the first li.splice of the array (2,0, "a") place "a" at index 2, 0 is fixed, must write Li.pop () delete the last element li.shift () delete element Li.splice (A, A, b), Starting with the element labeled A, delete the B element, including the element specified by subscript a li.slice (A, B) to the list, starting with the element labeled A, to the b-1 element cutoff m = Li.concat (b) Combining the arrays Li and array b. The merged element assigns a value to the array mli.reverse () to the Li Array, which reverses the value of the array itself, B = Li.join ("-") with "-" to connect the value in the array Li, and finally gets a string dic = {"K1": "V1"} Create a dictionary data type JS in serialization and deserialization of dic = {"K1": "v1"}s = json.stringify (DIC) serializes a dictionary into a string, S is a string b = Json.parse (s) deserializes a string into a dictionary, B is a dictionary for loop Li = ["A", "B", "C", "D"]dic = {"K1": "V1", "K2": "V2"}for (var item in Li) {console.log (item)} The result is: 0,1,2,3for (var Item in DIC) {Console.log (item)} The result is: The loop in K1,k2js is the print K value, where the K value of list defaults to subscript for (Var i=0;i<=100;i++) {Console.log (i)} JS also supports this for loop with the following example can be implemented in the print list of each element for (Var i=0;i<=li.length;i++) {Console.log (Li[i])} in the following way can be implemented in the printing dict each element for ( var k in dic) {Console.log (k,dic[k])}k1 V1K2 v2 while loop while (true): {Write execution statement} conditional statement if statement if (condition 1) {}else if (condition 2) {}else if (condition 3) {}else{}switch statement switch (name) {case 1:xxxxxxxcase 2:xxxxxxxdefault:xxxxxxxxxx} exception handling Try{xxxxxx}catch (e) {xxxxxxxxxx} FinallyThe {yyyyy} function defines a function func (ARG) {Console.log (ARG) return "Alex"}func (xxxxx) Self-executing function (function (args) {Console.log ( 22222)}) ("Alex") the outermost bracket means the equivalent of executing this function.

  

JavaScript Summary 1

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.