1. Using JS in HTML
<Script> Dosomething</Script><Scriptsrc= "Test.js"></Script><ahref= "Javascript:do Something">Link</a><Buttononclick= "Do Something">Button</Button>
PS: Multiple JS fragments or JS files in an HTML file are interlinked
2. Output
Alert (' Hello World ') // box output document.write (' Hello World ')/ / In-document output console.log (' Hello World ') //console panel output
3. Syntax
Naming conventions:
Naming to make sense
Cannot start with a number
Cannot use System keywords, reserved words
Case:
Case sensitive
Variable name and function name using hump naming (AAABBBCCC)
Object name uppercase per first letter (object)
Use of semicolons:
var true; // function execution statement, plus semicolon if (a) { console.log (' Hello world! ') ); } // struct definition statements, without semicolons
Comments:
Single-line Comment
/* * * Multi-line Comment
4. Variables
var variable name = variable value;
5. Data type
typeof ()//can be used for output variable types
Types include:
Number//digit, including integer and floating point (when processed or differentiated), because the floating-point number is approximate, do not use = = when judging
string//character; use + sign for connection, escape using \
// Example: var a = ' world '; Console.log (' \ ' Hello ' + A + '!\ '); // ' Hello world! '
Boolean//Boolean;
object//objects; array and null are also part of this class, but they are still distinguished when processed
function//functions;
Undefined//undefined;
6. Operators
Arithmetic operator +-*/% + +--
Assignment operator = + = = *=/=%=
Conditional operators > < = = = >= <= = = =!==
Logical Operators && | | ! ^
Bitwise operators >> >>> << | & ~
Ternary operator? :
7. Process Control
Sequential structure
Branching structure
if(BOOL) {...}//Single channel
if(BOOL) {...}Else{...}//Two-way
if(bool) {...}Else if(bool) {...}Else { ... } //multi-channel for range matching
Switch(var) { Casevalue1: ... Break; Casevalue2: ... Break; default: ... } //multi-path for single value matching
Loop structure
while(BOOL)//to judge the execution first, belong to the conditional type//Example:vari = 0; while(I < 100) {Console.log (‘#‘); I++; } Do- while()//perform the re-judgment first . for()//side judgment side Execution;//Example: for(vari=1;i<=9;i++){ for(varj=1;j<=9;j++) {Console.log (J+ "*" +i+ "=" + (j*i)); } console.log ("------------------");} Break //Exit LoopContinue //exit this cycle
Error handling
Try {...} Catch (e) {...} // attempt and error handling
@zhnoah
Source: http://www.cnblogs.com/zhnoah/
This article is owned by me and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original
The right to pursue legal liability.
JavaScript Learning notes--1. Basic knowledge