Javascript basics 1

Source: Internet
Author: User

Two years ago, when I relived the javascript Redbook javascript advanced programming, I used evernote to take notes on a temporary basis. In cnblogs over the years, I have read blogs from all of you, but I have never written public blogs. Now let's sort out the notes and hope to help you with the beginner's shoes ~ Javascript basics 1. There are two more articles later ~ There may be some text or expression problems, you are welcome to note the public link attached evernote: https://app.yinxiang.com/shard/s10/sh/81bef8e2-f56f-4f28-bb74-ed81f413de2c/3d14cd48699ce4a4a2cea8f55fe8f0cf identifier: starts with a letter, underline or dollar sign, other letters of an identifier can be letters, underscores, dollar signs, or numbers. Cannot Use reserved words, keywords, true, false, or null as identifiers. js case sensitive var is a keyword identifier. That is, the variable name is case sensitive. variables are defined without initialization (that is, values are assigned) the value is undefined. Undefined: undefined will be saved for any undefined or defined but uninitialized variables. If undefined variables are used, an error will be reported. Note that the variables defined in the function are local variables and will be destroyed when the function exits. Variables can save values of any type and change the type at any time. Data Types (6 types) 5 basic (simple) data types: Undefined, Null, Boolean, String, Number1 complex type: Objecttypeof operator returns a String eg: typeof "string" "undefiend"-this value is undefined or is not initialized "string"-this value is a string "boolean"-this value is a boolean value "number"-this value is a numerical value" object "-this value is null or the object" function "-this value is a function note: the returned string starts with a lowercase letter and is declared (defined) of the Undefined type. If undefined variables are stored in Undefined variables, an error is reported if they are directly used (except for the typeof operator) "undefined" is returned for all uninitialized variables of typeof and typeof ", thus, typeof cannot distinguish between the Defined variables and the uninitialized variables. It is recommended to initialize the Null type immediately after the variables are defined. The null value represents a Null pointer object! Var car = null; alert (typeof car); returns the object because null is actually a special object! If a variable is ready to save the object, it is better to initialize it to null, indicating that it is an object. You only need to check whether it is equal to null and whether the reference of an object is saved. That is, if the variable of the object to be saved does not actually save the object, you should explicitly let the variable Save the null value. Undefined is derived from null, that is, alert (null = undefined) returns true, but a type conversion occurs. The Boolean type has only two values: true and false. Note that all case-sensitive data types have values corresponding to the boolean type, which are implemented through the transformation function Boolean, note that the transformation function is automatically called in the judgment condition. Conversion rule of Boolean () (P23 in the Redbook) Number type value indicates that the value starting with not 0 indicates 10 hexadecimal (12), 0 indicates that the value starting with 8 indicates 8 hexadecimal (070 ), it starts with 0x and uses 16 as the base to represent hexadecimal notation (0xaf ). During operation, the value is always converted to decimal, and the result is also expressed in decimal. Floating Point Number: This value must contain only one decimal point and have at least one digit after the decimal point. Note that floating point numbers are automatically converted to integer floating point numbers in some cases, which may cause rounding errors. Do not test the value range of a specific floating point value: ECMAScript. MIN_VALUE to Number. MAX_VALUE is out of the range and is converted to a special Infinity, positive Infinity, and negative Infinity-InfinityisFinite () function to check whether it is between the maximum and minimum values. true is returned; otherwise, falseNaN is returned: A non-numeric value indicates that the number of operations to return a value does not return a value. Any operation involving NaN (such as NAN/0) returns NAN. In calculation, note that NaN is not equal to any value, including itself (only through isNaN () function to determine whether it is NaN), isNaN () tries to convert the input parameter to the numeric value conversion Number () function: You can input any numeric type if it is Boolean, true is 1, false is a numerical value of 0. It is simple to pass in and return Undefined, always return NaNNull, always return 0? Chorme25 returns the NaN string: If the string contains only numbers, it is converted to decimal. The leading 0 contains valid floating point numbers and is converted to a floating point number, similarly, the leading 0 contains a valid hexadecimal format (for example, 0xf) and is converted to decimal format (Note: octal cannot be identified and processed according to Rule 1, the returned 0 string contains all the characters except the preceding characters and is converted to the NaN object. The valueOf () method is called first and processed according to the preceding rules. If it is NaN, The toString () method is called again () method. ParseInt () function: only strings can be transferred. Principle: Ignore all spaces at the beginning to check whether the value mode is correct, if the first character not found by a space character is not a numeric character or a negative Number, NaN is returned. Note: The Null String parseInt () returns a non-numeric NaN, and Number () returns 0. If the first character is a numeric character, it is parsed until it is not a numeric character. Note: the decimal point is not a valid numeric character! ParseInt () can recognize various integer formats (octal, decimal, and hexadecimal). Note that the Number () function can only recognize decimal and hexadecimal formats. For example: parseInt ("0x15 ") returns 21 (16*1 + 5). For example: parseInt ("07"), returns 7. As a decimal 7 parseInt (), you can specify the conversion base, that is, the returned integer format, eg: parseInt ("010", 8); 8 is returned, and the result is also returned in octal notation. Note: When the base number is specified, the output of the string to be processed is the specified hexadecimal difference: number. in toString (), number is recognized as decimal, and number must be of the Number type. Then, return the value of toString () parseFloat () function based on the input base: it can only be transferred into a string similar to parseInt (). If the leading 0 is ignored, the first valid floating-point numeric character is found. the decimal point is valid. Therefore, the difference can be as follows: parseFloat () can recognize all floating point formats (refer to science The return value is not in the form of scientific Notation), but only the decimal value can be parsed. Any hexadecimal format will be converted to 0, and the octal value will be parsed in decimal format, because the octal value is 0 as the leading parseFloat () no conversion base parseFloat () can be used to parse a String type character literal escape sequence eg: \ B (Space) \ n (line feed) \ '\ "(escape single or double quotation marks) has the length attribute, which is valid for single-byte characters. The double-byte characters are not precise. The character string is unchangeable. Once created, their values cannot be changed. To change the value, you must destroy the original string and fill the variable with the new value string. String Conversion method. ToString () method. Each string has the toString () method, except for null and undefined values. When you call the Number type, you can input the base Number of the output value. That is, return the value of the specified valid hexadecimal string. For example: 10 .. toString (8), return 8, 10. toString (), and return 10. The default base is 10. This makes it easy to represent various hexadecimal numbers! However, only the decimal Number can call the toString () method. Other hexadecimal Number types are treated as decimal! That is, the value is output into a hexadecimal representation! Note Number .. toString () and Number. after the toString () difference is passed into the base number of the value, the returned value is the specified hexadecimal value, but to completely represent the hexadecimal value, you must add 0 and 0x to the octal and hexadecimal values as the String () method at the beginning. All types of values can be converted into strings, but null and undefined do not have conversion rules: Call the toString () method first. If so, call the String () method String () method: do not pass the parameter statement Note: There is no block-level scope in the same language as other languages. All the variables defined in the process control statement can be accessed by the process control. If statement: the condition can be an expression. if the result of the expression evaluation is not a Boolean value, then Boolean () is automatically called () to convert the result to obtain the Boolean for-in statement: it is a precise iterative statement that can enumerate the attributes of an object. Eg: var obj = {a: 1, B: 2}; for (key in obj) {console. log (obj [key])} // 1 \ n 2 note that the key is of the string type, so it cannot be accessed by vertices. You must use an object to access the switch statement: the parameters in switch () can be any data type, and can be numeric, string, or object. The value in case is not necessarily a constant. It can be a variable or an all-round operator executed in the expression switch, without type conversion.

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.