The book I bought last year but never see, leisure time looked down and found written inside the content is really good, so I decided to take notes while some learning on the blog, so easy to find and watch later.
- The best practice is on the js file <body> tag, which enables faster loading the browser page
- Statement (statement)
- Recommendations add a semicolon at the end of each statement, doing so make the code easier to read. Let each statement on a separate line approach can more easily track the order of execution of JavaScript scripts, such as
first statement;
second statement;
2.1 annotation (comment)
- // a single line comment
- / * Multiline
comment
* / - <-! HTML single-line comment ->, JavaScript is not required to do so, it will "->" as part of contents Notes, Note:
HTML allowed above <- -> comment span multiple lines, but! each row requires JavaScript must be at the beginning of this comment with "<! -" as a sign.
** Summary: To avoid confusion, we recommend using the "//" when the line is annotated with "/ *" comment multiple lines **
2.2 Variable (variable)
- The value of the deposit operation is called assignment
mood = "happy";
age = "22";
After a variable is assigned, say, the variable contains the word. Variable mood now contains the value "happy", now contains the variable age 22
- Note : JavaScript allows direct assignment of variables without prior declaration (declare), in JavaScript is not declared before assignment to a variable, the assignment will automatically declare the variable. Although JavaScript does not have to be forced to declare variables in advance, but to declare variables in advance is a good programming practice.
- A statement once again declare multiple variables and assignment completion
var mood = "happy";
var age = "22";
或
var mood = "happy",age = "22";
- In JavaScript, variables, and names of other syntax elements are case sensitive.
- JavaScript variable names are not allowed variable names contain spaces or punctuation marks ($ exception )
- Allowed to contain letters, numbers, dollar signs, and underscores ( but do not allow the first character is a number ). In order to compare greedy variable name with easy to read, you can then insert the variable name in place an underscore, such as
One way is to use the exception camelCased, such asvar my_mood = "happy";
var myMood = "mood";
Usually hump format is the preferred format function names, method names, and object properties named after.