JavaScript advanced programming (Third edition) Study Notes (2), javascript Study Notes

Source: Internet
Author: User

JavaScript advanced programming (Third edition) Study Notes (2), javascript Study Notes
Chapter 5

  • Literal representation
Var person = {name: "a", age: 10, 5: true // The value property name is automatically converted to a string };
  • "First name" contains a space, so it cannot be accessed using dot notation, but it can be accessed by person ["first name"]
  • Each item of the array can save any type of data.
Var c = new Array (20); // The length is 20var c = new Array ("red", "blue", "green"); // an Array containing three strings
  • When an item is added at the end of the array, its length attribute is automatically updated to reflect this change.
Var c = ["red", "blue"] c [99] = "green" // c. length = 100, access c [2] ~ C [98], return undefined
  • The Array value instanceof Array cannot be accurately determined when multiple global environments are detected.
  • Array. isArray (value)
  • Stack
    • Use the push () and pop () Methods of Arrays
  • Queue
    • Shift () and push () methods. Shift gets the first item and deletes the first item.
    • Unshift (): Add any item on the front end of the array and return the length of the new array.
  • Reverse () and sort ()
  • Concat () can create a new array based on all the items in the current array
  • Splice () method
    • Delete: delete any number of items. Two parameters. The first parameter indicates the position of the first item to be deleted, and the second parameter indicates the number of items to be deleted.
    • Insert: you can insert any number of items to a specified position. Three parameters. Start position, 0, and entry to be inserted
    • Replace: you can insert any number of items to a specified position. Three parameters.
  • IndexOf () and lastIndexOf ()
  • Iteration Method
    • Every () if each item returns true, true is returned.
    • Filter () returns an array composed of true
    • ForEach ()
    • Array composed of map () returned results
    • If any of some () values returns true, true is returned.
  • Zoom out Method
    • Reduce () reduceRight () (from the right)
    • Iterate all items to build a final returned value
  • Date type
    • Var now = new Date ();
    • Date. parse () accepts a character that represents a Date to create a parameter, and then tries to return the corresponding Date in milliseconds based on this string
      • Supported formats
        • 6/13/2004
        • January 12,200 4
        • Tue May 25 2004 00:00:00 GMT-0700
        • YYYY-MM-DDTHH: mm: ss. sssZ
      • If the date cannot be expressed, NaN is returned.
    • Date. UTC () returns the number of milliseconds of the Date
      • The parameters are surface, month (starting from 0), day, hour, minute, second, and millisecond. The first two must be
    • The Date constructor calls Date. parse () and Date. UTC (). The date and time are created based on the local time zone instead of GMT.
    • Date. now () returns the number of milliseconds of the Date and time when the method is called.
    • ToLocaleString () returns the date and time according to the format specified by the browser.
  • RegExp type
    • Var expression =/pattern/flags
    • Three Logos
      • G: does not stop when the first match is found.
      • I: case insensitive
      • M: multiple rows. When the end of the text is reached, the next row will be searched.
    • The main method of RegExp object is to use the exec () parameter as a string of the application mode.
      • The returned result is an array containing additional attributes index and input.
      • If it is in global mode, the next matching item is returned for each invocation of exec.
    • True when test () matches
Function sum1 (num1, num2) {return num1 + num2} var sum2 = sum1sum1 = nullsum2 (5, 5) // 10 can still be called
  • Understand Why js is not overloaded? Because the function defined later overwrites the previous function.
  • Internal Function Attributes
    • Arguments
    • Callee: indicates the function that owns the arguments object. arguments. callee
    • Caller: caller. Arguments. callee. caller
  • Function Method
    • Apply ()
      • Two parameters: one is the scope of the function to be run, and the other is the parameter array.
      • Call a function in a specific scope
    • Call ()
      • List all parameters
  • Basic packaging type
    • The basic type is not an object. Logically speaking, there is no way. The background automatically completes a series of Processing
      • Create an instance of the string type
      • Call methods on Instances
      • Destroy this instance
Var s1 = "some text" s1.color = "red" alert (s1.color) // The undefined instance has been destroyed.
var num = 10alert(num.toFixed(num)) // "10.00"
  • Number
    • ToFixed () is represented by a string that returns a value based on the specified decimal point.
    • ToExponential () Formatting numeric scientific count
    • ToPrecision () may return a fixed size or an index. Which of the following formats is the most suitable?
  • String
    • Concat () concatenation string
    • IndexOf lastIndexOf
    • Trim () deletes all spaces in front and suffix.
    • ToLowerCase toUpperCase case Conversion
    • Match mode match. If the parameter is a RegExp object or regular expression, an array is returned.
    • Replace the first parameter RegExp or string, and the second parameter is a string or function.
    • HtmlEscape escape is less than the number, greater than the number, and the number, double quotation marks
    • Split separates strings Based on delimiters and returns an array
  • Global Object
    • URI Encoding
    • EncodeURI
      • It is used for the whole URI and does not encode special characters of the URI, such as colons ,/,? #
    • EncodeURIComponent
      • Used for a section in URI
    • DecodeURI can only Decode Using encodeURI. Similarly, decodeURIComponent
  • The eval () parameter is a js statement string.
  • Math. random () 0 ~ 1, excluding 0 and 1
  • SelectFrom () two parameters, minimum and maximum (inclusive)

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.