JavaScript is a scripting language, called JS, simple structure, easy to use, the code can be placed directly into the HTML document, you can directly in the JavaScript-enabled browser to run. JavaScript makes Web pages more interactive, more vivid and more flexible. When you do something in the browser Web page, an event is generated, and the program written by JavaScript responds to the corresponding event.
JavaScript Basics Essentials:
First , JS three features
1) Case sensitive.
2) Weakly typed variables, define variables with the "var" keyword only.
3) JS Multiline comment with/**/for single-line comment//representation
second, the variable
1) The variable is declared by the keyword var.
2) Declare multiple variables at the same time with Var.
var girl= "jacom", age= "+", male= "false",
3) JS variable does not need to be initialized.
var couple;
4) Variable name rule:
The first letter of the ① must be either a letter (uppercase or lowercase), an underscore, or a dollar sign.
② the remaining letters can be underscores, dollar symbols, arbitrary letters, or numeric characters.
The ③ variable does not contain keywords.
5) Naming habits
Type |
Prefix |
Example |
Array |
A |
Aarray |
Boolean value |
B |
Bmale |
Floating point |
F |
FTax |
Function |
Fn |
Fnswap |
Integer |
I |
Iage |
Object |
O |
Ocar |
Regular |
Re |
Repattren |
String |
S |
Suniversity |
third, the data type
1) string
var smystring= "Hello World";
String Property methods
Properties |
Description |
example |
length |
Gets the length of the string |
|
charat |
Gets the character at the specified position |
< /td> |
substring |
Terminate position |
The content does not include that character at the terminating position, The second parameter defaults from the beginning of the bit to the end of the string. |
substr (start position, string length) IndexOf ("character") from go to search string a character Where first appears, if you find Less than return-1 indexOf ("character", start position) lastindexOf ("character") from backward LastindexOf ("character", Start position) |
2) value
3) Boolean type
4) Type conversion
① Numeric conversion character Special: var a=b=4 alert (1+b+c.tostring ());
Converting a numeric type to a string while implementing a binary conversion
② string to numeric type
parseint (), parsefloat () first checks the character at position 0, determines whether it is a finite number, does not return directly to isNaN, no longer operates, if it is a finite character, the position 1 characters are checked until a non-valid character is found.
5) array
①varl ateam=new Array (12); Array length 12
②var acolor=new Array (); Indeterminate length of array
a2color[0]= "Blue";
acolor[1]= "Yellow";
Acolor[2]= "Green";
Acolor[3]= "BLACK";
③ var ateam=New Array (1,2,3,4); Array length
④ parentheses define an array
⑤ Array to string
⑥ using the Join method to specify the connector between converted Strings
⑦ using the Split method to convert a string to an array
⑧ using the reverse method to reverse the array elements
⑨ using the Split method to arrange strings in reverse order
⑩ array element ordering using the Sort method
First knowledge of JavaScript