JavaScript Learning notes (i)

Source: Internet
Author: User

1.script element Async and Defer properties

Async: Asynchronous Script , when downloading scripts asynchronously, does not block the parsing of the document, but once the download is complete, the immediate execution will block the document parsing; (not necessarily in file order)

Defer: delay script , the script will be downloaded asynchronously but will not be executed immediately until the loading and parsing of the document is completed, and can be manipulated, the document will be executed; (in file order)

2.typeof null; "Object"

typeof regular Expression; "Object" (Safari5&chrome7 and previous return function)

Undefined derived from null:console.log (undefined = = null); True Console.log (undefined = = = null); False

3.number ("")//0;  parseint ("")//NaN;   Number ("1.1")//1.1; Number ("1.1.1")//NaN

Number (), parseint (), and parsefloat () return Nan for udefined and for strings that do not start with a number other than 0 digits; parseint () can be passed into the system number, parsefloat can not; Parsefloat allows a decimal points;

4. If an item in the array is null or Undefined,join (), toString (), the tolocalstring (), and the ValueOf () method return the result in an empty string representation;

Push ()// receives any number of arguments, adds to the end of the array, and returns the length of the modified array

Pop ()// removes the last item from the end of the array, reducing the array's length value, and then returns the removed item

Shift ()//Removes the first item in the array and returns the item, reducing the length of the number by one

Unshift ()// Add any item to the front of the array and return the length of the new array

Reverse ()//Reverses the order of array elements

Sort ()//Default Call the ToString () method after ascending; You can receive a comparison function that returns a negative number if the first argument should precede the second argument, or 0 if it is equal, or a positive number if preceded by the second argument;

function Compare (value1, value2) {     //  ascending---Smaller numbers arranged in front     return value1-  value2;  }  

Concat ()// Create a copy of the current array first, then add the received parameters to the end of the copy and return the newly constructed array

Slice ()//intercept array; You can accept one or two parameters, that is, to return the starting and ending positions of an item

Splice ()//three parameters are the starting position to delete, the number of items to be deleted, the item to be inserted

IndexOf () and LastIndexOf ()//param1 the item to find [param2] Find starting position

5.date.parse ("XX")//Return from UTC ( coordinated Universal time, international coordination times) 1970 c5> year 1 month 1 midnight (0 o'clock) the number of milliseconds to start to XX

Date.now ()// indicates the number of milliseconds of the date and time when this method was called (equivalent to +new date ())

6. Regular expressions

Need to escape the metacharacters ([{\ ^ $ |)? * +.]}

/*-------------------------------the link to be inserted----------------------------*/

7. Function declaration Elevation: The parser will take the lead in interpreting the function declaration and making it available before executing any code, whereas the function expression must execute to the line of code where it resides before it can be truly interpreted;

The arguments object contains a Callee property that points to the function that owns the arguments object;

Function object property Caller: Contains a reference to a function that invokes the current function;

This refers to the environment object to which the function is executed;

In strict mode, using Arguments.callee will result in an error, and assigning a value to the caller property of the function will also cause errors;

The prototype property is not enumerable;

※ Each function contains two non-inherited methods: Apply () and call (); The purpose of the two methods is to call the function in a specific domain, which is actually equal to the value of the this object in the body of the function

The Apply () method receives two parameters: the first parameter is the scope in which the function is run, and the second is the parameter array;

The call () method is different from the method of receiving the parameter, the first one does not change, the remaining parameters must be passed directly to the function (that is, the function needs to enumerate the parameters);

The Bind () method creates an instance of a function whose this value is bound to the value passed to the bind () function;

8.Number Type method:

ToFixed (): A string representation of the value returned by the specified decimal place; IE9 and previous bugs;

toexponential (): Returns the string form of a numeric value expressed in exponential notation;

toprecision (): A fixed size may be returned ( fixed Format , or it may return an exponential (exponential) format, which is the most appropriate format to see.

String type:

CharAt (): Returns the character of the given position as a single-character string; charCodeAt () returns the encoding of that character; (ES5 can be obtained directly using square brackets and indexes);

Concat (): stitching string, equivalent to +

Slice () , substr () and the substring ():/*----------------------------the link to be inserted------------------------*/;

the index () and lastindex () methods are the same as arrays; trim (): Delete all spaces in front and back; toUpperCase ()/tolowercase Case Conversion

Match (), search (), replace (), split (), Localecompare (), Formcharcode ()

9.Global Object encodeURI (), encodeURIComponent (); decodeURI (), decodeuricomponent ();

The Math object Math.min () Math.max () Math.ceil () rounds up Math.floor () rounding down Math.Round () rounding Math.random ()//[0.1)

JavaScript Learning notes (i)

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.