JS (1)

Source: Internet
Author: User
Tags java keywords

The JavaScript authoritative guide read the notes after reading

1. Reserved keywords for ECMAScript 5: class,const,enum,export,extends,import,super;

2. ECMAScript 3 Lists all Java keywords as their reserved words;

3. Separator ";":

    • Missing delimiter, the end of a statement is the beginning of the next statement, and vice versa;
    • Exception one, and then the Return,break,continue statement, if the three keys followed by a newline, JS will automatically fill the semicolon at the line;
    • Exception two, "+ +", "--" self-decrement symbol, can be a prefix or suffix, otherwise the end of the line to fill the semicolon, the self-increment or decrement symbol as the next line of code prefix operator and together with it parsing.
      1 a 2 + +3b4// resolved to A;++b;

4. Type, value, variable

(1) JS data types are divided into: primitive Type, Object type

    • Primitive type: Number (integer:-253 ~253, floating point: -5*10-324 ~ 5*10-324), String, Boolean, special original value (nul: null, undefined: undefined);
    • Object type: Object, array, function, object is a collection of property properties, each property consists of a name/value pair, and the value can be the original value or an object.

(2)

var x=.3-. 2;
var y=.2-. 1;
x = = y; False
x = =. 1; False
y = =. 1; True
JS in 0.3-0.2=0.099 999 999 999 999 98;

(3) Date and time var now = new Date ();

 1  var  now= new   Date ();  2  now.getfullyear (); //  year  3  now.getmonth (); //  month, starting from zero  4  now.getdate (); //  The first few months of the month, starting from the first few  5  now.getday (); //  Day of the week, 0 for Sunday  6  now.gethours (); //  local time  7  now.getuthours (); //  time for hours using UTC, based on time zone  

(4) string

1  varS= "Hello,world";2S.charat (0);//H Gets the first few characters, here is the 0th3S.charat (s.length-1);//D4S.substring (1,4);//ell intercepts four characters, since the index is starting at 0, so it is from 2nd to 4th, but not 4th5S.slice (1,4);//ell6S.slice (-3);//Rld last three characters7S.indexof ("L");//2 first occurrence of position8S.lastindexof ("L");//9 Last occurrence of position9S.indexof ("L", 3);//3 Position first appearing after position 3 and afterTenS.split (",");//["Hello", "World") split into sub-strings OneS.replace ("H", "H");//Hello,world Full-text character substitution AS.touppercase ();//Hello,world convert characters to uppercase letters

(5) RegExp ()

1 vartext= "testing:1,2,3";2 varpattern=/\d+/g;//match all instances that contain one or more numbers3Pattern.test (text);//the True Test () method is used to detect whether a string matches a pattern.4Text.search (pattern);/*the 8 Search () method is used to retrieve the substring specified in the string,5 or retrieves a substring that matches the regular expression. 6 returns 1 if no matching substring is found. 7                             */  8Text.match (pattern);/*["1", "2", "3"]9 The Match () method retrieves the specified value within the string .Ten or find a match for one or more regular expressions.  One if no matching text is found, match () returns NULL.  A Otherwise, it returns an array that holds information about the matching text it finds. */ -Text.replace (Pattern, "#");//testing:#,#,# -Text.split (/\d+/);//["", "1", "2", "3"]

(6) null and undefined

Null is commonly used to represent "null", execute a typeof budget, and the result is returned as object, which means that null can be considered a special object value, meaning "non-object", in fact.

Undefined also represents the vacancy, executes the TypeOf budget, returns the result as undefined, and represents a deeper "empty value" with an undefined value. It is a value of the variable that indicates that the variable is not initialized. If you want to query the value of an object property or array element, the return undefined indicates that the property or element does not exist, and that the reference does not provide the value of the function parameter that is the argument is also obtained undefined. ECMAScript 3 undefined is readable/writable and can be arbitrarily assigned, undefined is read-only in ECMAScript 5.

Both null and undefined are "worth a vacancy," and both are usually interchangeable, with the value "= =" being true, and both the "= = =" Values of false;null and undefined do not contain any properties and methods.

It may be considered that undefined is a worthwhile vacancy that represents a system-level, unexpected, or similar error, and NULL is a program-level, normal, or expected vacancy. The best choice is null if you want to pass the parameter.

(7) Global objects

    • Global properties: such as undefined, Infinity, NaN;
    • Global functions: such as IsNaN (), parseint (), eval ();
    • Constructors: such as Date (), RegExp (), String (), Object (), Array ();
    • Global objects: such as Math and JSON;

The initial properties of global objects are not reserved words, but they should be treated as reserved words.

(8) Packaging objects

The temporary object that is created when accessing properties of strings, numbers, and Booleans is called wrapper objects, and it is only occasionally used to differentiate between string values and string objects, numeric and numeric objects, Boolean values, and Boolean objects.

(9) Comparison of object values is a reference comparison: they are equal when and only if they reference the same base object.

(10) Type conversion

  • ToString (Radix): Radix is an optional parameter, and if you do not specify this parameter, the conversion rule will be based on decimal. The value of radix is 2~36.
    1 var n=17; 2 str1=n.tostring (2);  // convert to "10001" 3 str2= "0" +n.tostring (8);   // convert to "021" 4 str3= "0x" +n.tostring (+);   // convert to "0x11"

  • ToFixed () Converts a number to a string based on the specified number of digits after the decimal point (rounded or supplemented by 0);
  • Toexponential () uses exponential notation to convert a number to a string in exponential form, where there is only one digit before the decimal point, and the number of digits after the decimal point is determined by the parameter; (rounded or supplemented 0);
  • Toprecision () Converts a number to a string based on the specified number of significant digits. (There is rounding or supplementing 0);
  • Number () converts the passed-in string to a certificate or floating-point direct amount. Conversions are based on decimal numbers only. ;
  • parseint () resolves integers only; (any number of leading spaces will be skipped);
  • parsefloat () resolves integers and floating-point numbers (any number of leading spaces will be skipped);
    1 varn=123456.789;2n.tofixed (0);//1234573N.tofixed (2);//123456.794N.tofixed (5);//123456.789005N.toexponential (1);//1.2e+56N.toexponential (3);//1.235e+57N.toprecision (4);//1.235e+58N.toprecision (7);//123456.89N.toprecision (10);//123456.7890

All objects inherit two conversion methods

    • ToString ()
    • ValueOf () simply returns the object itself, such as a date type, which returns the number of milliseconds directly.

(one) JS function scope, declaration in advance

    • function scope: Refers to all variables of life within a function are visible in the function body. This means that the variable is even available before the declaration. This feature is informally referred to as a declaration in advance.
    • In some C-like programming languages, each piece of code within the curly braces has its own scope, and the variables are not visible outside the snippet that declares them, which we call block-level scopes. JS does not have block-level scopes.

(12) When a variable declared with VAR is used, the property created is not configurable and cannot be deleted by the delete operator.

1 var o1=1; 2 o2=2; 3 this. o3=3; 4 delete O1;  // false The  variable is not deleted 5 delete O2;  // The true   variable is deleted 6 Delete O3;  // true   variable is deleted

JS (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.