JavaScript Advanced Programming (3rd Edition) Chapter III (Basic Concepts)

Source: Internet
Author: User
Tags bitwise bitwise operators

3.1 Syntax

1. Numbers that do not start with numbers, letters, underscores, dollar signs

2. Comments: HTML <!----> css/**/JS single line//multiline/**/

3.ES5 introduced the strict mode (strict modes). is a different parsing and executing model for JS definition. You can include "use strict" above the entire script header or function to enable strict mode (Ie10 above supports strict mode)

3.2 keywords and reserved words

3.3 Variables

The 1.ECMAScript variable is loosely shaped. That is, each variable is just a placeholder for holding the value.

There is no rule that defines a variable that must hold the value of that data type, and the variable "JS" is more "dissolute" (not "consistent") relative to the variables in other languages.

2. Uninitialized variables, a special value is saved-----undefined.

3. Using a variable that is not declared (defined) will be reported referenceerror defined.

3.4 Data types

1.typeof ① Result: Undefined,number,string,boolean,obeject (the value of object and NULL, NULL is an empty object reference); function

② two usages: typeof 1; typeof (1)

2.undefined (values that have been defined, uninitialized)

Defined (undefined)

3.null null reference

null and undefined equal (= =) not congruent (= = =)

4.boolean empty string, 0 and nan,null,undefined = = "false"

5.number① The memory space required to hold floating-point values is twice times the value of the saved integer.

② can use scientific notation (e) to denote floating-point number 3e2 = 3*10 of 2 times = 3*100

The highest precision of the ③ floating-point number is 17 digits.

④ floating point calculation generates rounding error problems. (Common problems with floating-point calculations based on IEE754 values)

0.1+0.2 = 0.30000000000000004

⑤isfinite (num) determines whether NUM is infinite

⑥nan is not equal to any value, including NaN itself IsNaN judging whether it can be converted to a value

IsNaN (Nan) True NaN is a special numeric type

IsNaN ("Blue") false

IsNaN ("one") false

⑦number () "", NULL, False = "0

Undefined= "NaN

Ignore leading 0, cannot parse octal

⑧paseint () "", null, undefined = "NaN

Ignore leading 0, cannot parse octal so add second parameter: Paseint ("0x16", 16) cardinality 16 without quotation marks

Stops when a string that cannot be converted is encountered.

⑨pasefloat () resolves when the first decimal point is valid and the second decimal point is invalid.

Ignoring the leading 0, only 10 digits are parsed, and the 16 binary strings are converted to 0

// 1234 pasefloat (//  0pasefloat (/ // 1.9

    6.string () Modify the string: To change the value of a string, "destroy" the original string. "Fills" the new string.

This process is done in the background. So in some older versions of the browser, stitching strings is slow.

①tostring () converted to string, null and undefined without this method

ToString (num) can output a string value represented by any valid NUM format

② transformation function string ();

7.object

3.5 operator

1. unary ① forward increment/decrement (1) For example:--a; First decrement 1 and then participate in the operation

var a = 2;var b =--a + 2//1//3

② Increment/decrement (1)

var a = 2;var b = a--+ 2//1//4

2. Bitwise operators ① negative binary codes, using twos complement

Ask for twos complement: A, binary code B with absolute value, binary inverse code (0->1,1->0) c. Binary code +1 formula: Positive, reverse, +1

①ecmascript all values are saved in a 64-bit format, but the bitwise operator does not directly manipulate the 64-bit value. Instead, convert the value of 64 to 32, manipulate 32 bits, and finally turn the result into 64-bit.

② bitwise non-intrinsic:-operand-1

var n =; var n1 = ~////-25-1

③ Bitwise AND & (10 binary-"2 binary 16 8 4 2 1)

④ Bitwise OR | ⑤ bitwise XOR OR with | The difference, 1&1= 0;

⑥ (signed) shift left <<, without affecting symbols

⑦ (Signed) Right shift >>, without affecting symbol

⑦ (unsigned) Right shift > >>, influence symbol (note negative is complement)

3. Boolean operator ① logical non! ② Logic and && short circuit with (a, a false false B, the first one is false will not judge the second operand)

              

var false  //BBBBB is a variable that is not defined. Under normal circumstances, it would prompt refrenceerror defined.

③ Logic or | | Short-circuit operator The first one is true and then the second operand is not judged

var true  //BBBBB is a variable that is not defined. Under normal circumstances, it would prompt refrenceerror defined.

4. Multiplicative operator (*/%)

5. Additive operator ①+ If one operand is a string, the other is also converted to a string

②0-0 = 0; 0-(-0) = 0;-0-(-0) = 0;

6. Relational operators ①> < <= >=② If one operand is a numeric value, the other operand is also converted to a number;

③ if 2 operands are strings, compare the character encodings of 2 strings (the character encoding of uppercase letters is less than the character encoding of lowercase letters)

var tre = "A" < "a";   // true console.log ("All" <  "3");  // true  (Here are all strings)

7. Equality operator ①== comparison is the value (first conversion and then comparison) ②=== comparison is the type (only comparison does not convert)

Special case: null = = undefined; (Remember it)
8. Conditional operator (? :) ①

var a = 1> 2?1:2;   // A = 2

9. Assignment operator = + = *=-=/=%=

10. The comma operator ① is used to perform multiple operations (eg: declaring multiple variables)

3.6 statements

   1.if ① always use {}② always use code block branch

2.do-while(post-test cycle)

3.while(front test cycle)

4.for ① i, defined inside the loop, can still access it externally.

②for (;; ) Infinite loop

5.for in ① can enumerate object properties

The properties of the ②ecmascript object are not in order. Therefore, the order of the property names that are output through the for-in loop is unpredictable.

③ if the value of the iteration object is null or undefined, the loop is not executed

④for (var x in arr)

6.label Statements

7.break and Continue ①break immediately exit the loop, forcing the statement after the loop to execute

       var num = 0;   for (var i = 0; i < i++) {  if(i) 5 = = 0) {  break+ +//num = 4;i = 5

②continue exits the loop immediately, continuing from the top of the loop.

       var num = 0;   for (var i = 0; i < i++) {  if(i) 5 = = 0) {  continue+ +//num = 8;i = 9

③ is used in conjunction with the label statement.

The 8.width statement ① to simplify the work of writing the same object multiple times.

           Width (location) {         var url = href; }

The 9.switch operator uses the congruent operator

3.7 Functions

1. Functions in ECMAScript, parameters are represented by an array. The function touches the array at all times, regardless of which parameters are included in the array. So even if the defined function accepts 3 parameters, it is not necessary to pass 3 parameters in the use, which can be less transmitted, more transmitted and not transmitted.

Inside the function body, the parameter array is accessed through the arguments object.

2.arguments.length can tell how many parameters are transferred to a function

3.function fun1 (num1,num2) {}

The values of NUM1 and arguments[0] are synchronized, but their memory space is independent.

4. Overloading: In other languages, such as Java, you can write 2 definitions for a function, as long as the signatures of the 2 function definitions (the type and number of parameters accepted) are different.

In ECMAScript, the parameters are represented in an array, so the parameters are the same type and quantity for the function, so there is no signature and no real overloads.

JavaScript Advanced Programming (3rd Edition) Chapter III (Basic Concepts)

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.