Directory:The first chapter essenceChapter II SyntaxChapter III ObjectsFourth Chapter functionFifth Chapter SuccessionSixth Chapter ArraySeventh-Regular ExpressionsEighth Chapter MethodThe nineth Chapter code style
Chapter One: Essence
···· I just have a few pleasing places, how can there be any fascinating magic? --William Shakespeare
Chapter II: Grammar
1. Notes :
a). Note Be sure to describe the code exactly, and the unused comment is worse than no comment.
b). JavaScript provides two ways to annotate *//and/, respectively, for multiple lines and single lines, but multiline annotations are sometimes unsafe, such as when using certain regular expressions:/* var a =/a*/.match (s);
* / It is recommended to avoid using the/* */comment, or//instead.
2. numbers:
a). JavaScript has only one numeric type, which is represented internally as a 64-bit floating-point number, and Nan is a numeric value, but it is not equal to any value, including itself, and IsNaN (number) can be used to detect Nan;
b). Numbers have the Math () method, such as Math.floor (number), which can convert a number to an integer.
3. string:
a). JavaScript does not have a character type, to indicate that it simply creates a character string.
b). The string has a length property. For example: "text". Length equals 4
c). \ (backslash) is an escape character. strings that can be inserted in characters that are not allowed in normal situations. \u conventions are used to specify numeric character encodings: "A" = = = "\u0041"
d). The string is immutable, and once the string is created, it can never be changed. Of course you can use the + operator to link different strings, but that is the creation of a new string, not a modification.
e). String also has some methods, such as: "Test". toUpperCase () = = = "Test". (detail)
4. statement:
A). Statements are usually executed from top to bottom, but JavaScript can change the order of execution through conditional statements (if, switch), loop statements (while, for, do), Force challenge statements (break, return, throw), and function calls.
b). In JavaScript, the code block statement inside the curly braces does not create a new scope, so the variable should be defined in the head of the function, not in the code block.
c). If statement:
if (ture) { // False value: false/null/undefind/'/0/nan. Truth: The other values are true, and the string "false" also counts as // True when executing the code in this }Else{ // False value when executing code in this }
d). Switch statement:
Switch (test) { Case 1: //break : Case "A": // break : default: // break :}
e). For statement (two cases):
for (var i = 0; i < i++ ) {// This statement executes 10 times }for in obj) { //obj is a set of objects, MyVar is the property of the object if(Obj.hasownproperty (MyVar)) { // This method checks whether a property exists }}
f). While and do While statements:
while (condition) { // code to execute }do{ // code to be executed, The condition is executed once } while (condition)
f). Other statements
Try { // Execute code Throw// Throw custom Exception return; // return to re-execution } Catch (Error) { // handling error break // forced exit }
The language of JavaScript learning notes