Javascript learning notes _ basic syntax, type, variable, and javascript learning notes

Source: Internet
Author: User

Javascript learning notes _ basic syntax, type, variable, and javascript learning notes

Basic syntax, type, and variable

Non-numeric values: (since Infinity and NaN are not equal to any value, including themselves)

1. Use x! = X. true is returned only when x is NaN;

2. isNaN (x) is used. If x is NaN or a non-numeric value, true is returned;

3. If isFinity (x) is used, true is returned if x is not NaN, Infinity, or-Infinity;

Although (strings, numbers, and boolean values) are not objects, their attributes are read-only, they can also reference their attributes and methods like operation objects. The principle is as follows:

Javascript constructs a temporary object (called a wrap object) of String, Number, and Boolean, and then calls its attributes and methods through this temporary object, these properties and methods change only the temporary object, and the temporary object will be destroyed. The changes do not affect the original data;

You can create a packaging object explicitly. Its value is equal to the original data '=', but its type is different '='

Number a to string:

A. toString (n) // n indicates hexadecimal

A. toFixed (I) a. toExponential (I) a. toPrecision (j) // I is the number of decimal places, and j is the number of digits to be displayed

String s to decimal number: (ignore leading space, convert as many numbers as possible, ignore the following non-numeric content, '0x 'and '0x' are converted in hexadecimal notation)

ParseInt (s, [n]) // n indicates the hexadecimal notation. An optional parameter converts s to the decimal notation in the presence of n.

ParseFloat (s, [n])

To automatically convert an object to a string:

1. If there is a toString () method and it can return the original value, call it to convert the returned original value to a string;

2. If the first step is invalid, call valueOf () to convert the returned original value to a string;

3. If the first two inconsistencies are invalid, a type error exception is thrown;

Steps to automatically convert an object to a numeric value:

1. If valueOf () exists, call it to convert the returned original value to a number. This number can be returned;

2. If option 1 is invalid, call toString () to convert the original value to a number and return the number;

3. If neither 1 nor 2 is valid, a type error exception is thrown;

The Date object is an exception

Variable declaration in advance:

When an undeclared variable is called, the declared part of the variable is prefixed during compilation, and the initialization part is left in the original place;

(The declared variable will partially overwrite the external variable)

var s1 = 'ggggg';function f() {console.log(s1); //s1 == undefinedvar s1 = 'cccccc';console.log(s1); //s1 == 'cccccc'}

Bit operation: & | ^ ~

&: Perform the AND operation on the two integer operands of bitwise AND. The result is 1 only when the corresponding bitwise is 1;

|: Bitwise OR. If one of the corresponding bits is 1, the result is 1;

^: Returns the bitwise XOR. If the bitwise is the same, the value 0. If the bitwise is different, the value 1;

~ : Bitwise inversion, unary operator, all bitwise inversion, equivalent to changing the symbol and reducing 1;

(N is 0 ~ Between 31)

<N: shifts all digits n places to the left. The value is multiplied by the n power of 2, and the leftmost n digits are discarded. The n digits on the right are supplemented with 0;

> N: all bits are shifted to n bits. Ignore the overflow bits on the right and fill the left bits with the original operands. The result is equivalent to the n power except 2, discard the remainder, 7> 1 = 3, -7> 1 =-4

<N: Same <, only 0 is used to fill the left Digit

Comparison size between strings:

A JavaScript string is a character series composed of 16 integer values. Strings compare the values of their characters. The values of uppercase and lowercase characters are different;

Comparison operators prefer numbers. As long as one operand is a number, numeric operations are performed. String comparison is performed only when both are strings.
 
The '+' operator prefers strings. As long as one of the operands is a string, String concatenation is performed.

X in p

Check whether property x exists in object p, INCLUDING THE METHOD

A instanceof

Check whether object a is an instance of Class A, including the detection of its parent class
 
False: false, null, undefined, 0,-0, NaN ""

True Value: All values except the preceding values are true values;

Object: Except for strings, numbers, true, false, null, and undefined, other values are all objects!

The above is the javascript learning notes for everyone. I want to help you with the basic syntax, type, and variable content ~

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.