A. Overview
1. Output tool:
()---can be html
alert()---String
prompt(text,defaultText)
text----Optional. Plain text to display in the dialog box (rather than text in HTML format).
defaultText---Optional. The default input text.
Placement
a. Can be placed anywhere in HTML
b. But he is a whole, influences each other
c. In the location of hyperlink and redirect
<a href="javascript:alert();"></a> <form action="javascript:alert();"></form> <div onclick="alert()"></div> ********IEIt is feasible,Not recommended******** <div ></div> <script for="one" event="onclick"> alert(111); </script>
d. Call external javascript file
<script src=""></script>
1. No code can appear in the called js tag
The <script> tag cannot appear in the script
3. It is still interconnected and influential
3. Comments
a. For old browsers
<!-- -->
*If the old browser does not recognize JS, comment
b. Real comment
In-line comments //
Block comment /* */
B. Variables
1. Naming Specifications
a. Strictly case sensitive
b. The naming of a variable must begin with a letter or _ or $; the rest can be any letter, number, _, $
c. Cannot be named with keywords or reserved words
Keywords: for, if, try, etc.
Reserved words: byte, char, class, etc.
d. Naming Specification
Hump nomenclature: getElementById
Capitalization of the initial letter: Object
Meaningful naming: name, age
2. Variable: A variable that can store data
a. How to create variables (** Must be modified with the var keyword**)
Declare first, then assign value: var a;a=3;
Declaring assignment is performed simultaneously: var a=3;
Declare multiple variables at once: var a, b, c;
Declare multiple variables at once and assign values: var a=1, b=2;
b. How to overwrite existing variables
1. If the variable is changed from a new declaration without assignment, the value of the variable will not change.
var a=1;var a; result a=1;
2. If the variable is changed from a new declaration and the value is assigned, the value of the variable is changed to the new variable value.
var a=1;a=3; result a=3;
3. No keyword var to modify variables
a;alert(a); report an error
a=1;alert(a) Result: 1
If you do not use var to modify it and there is no assignment ----an error is reported; if there is assignment, js will be treated as a global variable and will not report an error. (The latter is not recommended)
C. Data type
typeof() operator: a unary operator used to detect data types, and the returned result is always a string
The isNaN() function is used to check whether its parameters are non-numeric values.
1. Initial Type
--The variable is not assigned after creation, and its default value is undefined
--Nothing, only one placeholder
--Shaping, floating point type; supports two, eight, ten, and hexadecimal systems, all output in decimal systems; special values
1. Two, octal: start with 0
2. Hexadecimal: Start with 0x
3. Special values:
Maximum: Number.MAX_VALUE
Minimum: Number.MIN_VALUE
Infinity: Infinity
Infinity
--Standard surrounded by odd and double quotes, and some special characters
1. The efficiency of odd and double quotes is the same (different from PHP)
2. Only appear in pairs, not interchangeably
3. Can nest var a="a '11' ";
4. Special characters
\n Line break
\t Tab characters
\b Space
\r Line break
\' Single quotes
\" Double quotes
\\ Slash
2. Reference Type
type | value | typeof return value |
undefined | undefined | undefined |
null | null | object |
boolean | ture,false | bollean |
string | Values between odd and double quotes, special symbols | string |
When you first enter the front end, if you have any shortcomings or misinformation in the writing, you will hope that all the masters will give you guidance and encourage them to make progress together.