JS Advanced Programming Learning Note 1

Source: Internet
Author: User
Tags bitwise bitwise operators

Why JavaScript is generated:

In the age of dial-up, the form data must be sent to the server to verify that the input is valid, and JavaScript is developed to solve this problem so that the client can verify the validity of the input values.

Ecmascript/javascript:

JavaScript is the scripting language Netscape company published in 1995, and ECMAScript is the syntax and semantics of a generic, cross-platform, vendor-neutral scripting language defined by the European Computer Manufacturers Association.

A complete JavaScript implementation consists of:
    1. Core (ECMASCRIPT): defined by ECMA-262, providing core language functions;

    2. Document Object Model (DOM): An API that was originally intended for XML but was extended to HTML.

    3. Browser object Model (BOM): Provides methods and interfaces for interacting with the browser;

Two reasonable ways to speed up page loading:
    1. Place JS <script> tags at the bottom of the page.

    2. Add the Async attribute to the <script> tag.

Number type:

Numeric conversions have a total of three functions: number (), parseint (), and parsefloat ().

Number () Conversion rule:
    • The Boolean values are converted to 0 and 1.

    • Numbers are simply incoming and returned

    • Null value returns 0

    • Undefined, returning Nan

    • In the case of integers, floating-point numbers, hexadecimal, the corresponding number is converted to decimal, ignoring the leading 0.

    • An empty string is converted to 0, and the other is Nan

    • If it is an object, call the ValueOf () method first, convert from the previous rule, and, if it is Nan, call the ToString () method, and then convert by the previous rule.

parseint () Conversion rules:

Ignores the spaces in front of the string until the first non-whitespace character is found earlier. If it is not a numeric character or a minus sign, Nan is returned. Until it resolves to the first non-numeric location. It is a good idea to give the function a second argument, the cardinality to use when converting.

Parsefloat () Conversion rules:

Only the decimal is parsed, the 16 binary, and so on, is returned 0. And only one decimal points are parsed.

String type:

ToString () Method:

1. Applicable numeric type: numeric value, Boolean value, object, and string.

2. For numeric types, you can pass a parameter as the base of the conversion.

String () Method:

1. You can convert any type, NULL, and undefined return itself.

Operator:

1. Unary operators

    • The forward increment decrement operator changes the value of a variable before the statement is evaluated.

    • The post increment decrement operator changes the value of a variable after the statement is evaluated.

2. Bitwise operators

    • ~ bitwise NON (not) returns the complement of numeric values 。

    • & Bitwise AND (and), Convert the value to 2, each alignment, two corresponding bits are 1 o'clock return 1, otherwise return 0.

    • | bitwise OR (OR), a bit is 1 and returns 1.

    • ^ Bitwise XOR (XOR), only one bit is 1 is returned 1, otherwise returns 0

    • << left shift, Shifts all bits of a numeric value to the left by the specified number of digits, and left without affecting the symbol bit

    • ; > Signed right SHIFT, moving values right, left with sign bit to fill all vacancies

    • ; >> unsigned Right shift, positive number not affected, but negative number left with 0 padding, Makes it a very large value

3. Boolean operators

    • Logical AND logical or short-circuit operators, as long as the first operator evaluates to true, the second value is not evaluated.

4. Conditional operators

Variable = boolean_expression? True_value:false_value;

Statement:

1.do-while statement: A post-Test loop statement, the code most commonly used in a loop body is executed at least once.

2.while: Pre-Test loop statement.

3.for: Pre-Test loop statement

4.for-in: A precise iteration statement used to enumerate the properties of an object.

5.switch statement:

1 Switch (expression) {2      Case value:statement 3      Break ; 4     default : statement; 5 }

6. Function: The return statement of a function can have a return value, or no, no return value means that you want to stop the function execution prematurely and do not need to return a value.

7. Function: JS does not mind how many parameters, but also do not mind the type, the function body can be accessed through the arguments object to this parameter array, so as to get passed to the function of each parameter. Named parameters are just a convenience, but not a necessity.

8.js is not overloaded, two functions with the same name, the name only belongs to the function defined later.

Values for the base type and reference type:

1. The basic type refers to a simple data segment, which is 5 basic data types. These 5 basic data types are accessed by value and can manipulate the actual values that are saved in the variable.

2. Reference types refer to objects that may have multiple values. When you manipulate an object, you are actually manipulating its reference, and the value of the reference type is accessed by reference. The value of a reference type can be dynamically added to the property.

copy variable values:

1. Copy the value of the base type, create a new value on the variable object, and then copy the value to the location assigned to the new variable, after which the two variables can participate in any operation without being affected by each other.

2. For copy of reference type, copy the value stored in the variable object into the space allocated for the new variable. But the two replicas are actually the same pointer, and after the copy is finished, two variables will actually refer to the same object, so changing one of the variables will affect the other variable.

Pass Parameters:

The parameters of all functions in ECMAScript are passed by value. A base type is worth passing as a copy of a primitive type variable, whereas a reference type's passing is like copying a reference variable. (even if the parameter values are modified inside the object, the original reference remains unchanged).

Detection type:

The 1.typyof operator determines whether a variable is the best tool for a string, numeric value, Boolean, or undefined.

The 2.instanceof operator can determine what class an object is.

extend the scope chain:

The catch block of the 1.try-catch statement creates a new variable object that contains the error object declaration that was thrown.

2.with statement, the specified object is added to the scope chain.

function BuildUrl () {    var qs = "Debug=true";      with (location) The {              //Locationobject contains all the properties and methods        var url = href + qs;     // The actual reference is Location.href     }    return URL;                  // URL is part of the function execution Environment }

There is no block-level scope:

1. In JS, the variable declaration in the IF statement adds the variable to the current execution environment.

1 if(true) {2     var color = "Blue"; 3 }45 alert (color);        // "Blue", typically in C/c++/java, color is destroyed after the IF statement is executed. 

When you write a JS code, you initialize the variable without declaring it, and you make it into a global variable.


JS Advanced Programming Learning Note 1

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.