Javascript learning notes (overview, variables, data types), javascript learning notes
A. Overview
1. Output tool:
Document. write () --- It Can Be html
Alert () --- string
Prompt (text, defaultText)
Text --- optional. Plain text to be displayed in the dialog box (instead of HTML text ).
DefaultText --- optional. Default Input text.
2. js placement
A. It can be placed anywhere in HTML.
B. But he is a whole and affects each other.
C. The position of the hyperlink and redirection
<A href = "javascript: alert ();"> </a> <form action = "javascript: alert (); "> </form> <div onclick =" alert () "> </div> ******** IE is feasible, * <div id = "one"> </div> <script for = "one" event = "onclick"> alert (111) is not recommended); </script>
D. Call an external javascript file
<Script src = ""> </script>
1. No code can appear in the called js tag
2. The <script> label cannot appear in the js script.
3. mutual connection and Influence
3. Notes
A. For the old browser
<! -->
* If the old browser does not recognize JS, comment
B. Real comments
Intra-row comment //
Block comment /**/
B. Variables
1. Naming rules
A. Strictly case sensitive
B. The variable name must start with a letter or '_' or '$'. The rest can be any letter, number, '_', or '$ '.
C. You cannot use keywords or reserved words for naming.
Keywords: for, if, try
Reserved Words: byte, char, class, etc.
D. Naming rules
Hump name method: getElementById
Uppercase letter: Object
Meaningful names: name and age
2. Variable: a variable that can store data
A. How to Create a variable (** it must be modified with the var keyword **)
Declare first, and then assign the value: var a; a = 3;
Declare and assign values simultaneously: var a = 3;
Declare multiple variables at a time: var a, B, c;
Declare multiple variables at a time and assign values: var a = 1, B = 2;
B. How to overwrite existing Variables
1. If the change volume is declared and no value is assigned, the value of the variable will not change.
Var a = 1; var a; Result a = 1;
2. If the change volume is declared and assigned a value, the value of the variable is changed to the new value.
Var a = 1; a = 3; Result a = 3;
3. Variable modification without the keyword var
A; alert (a); Error
A = 1; alert (a) Result: 1
If var is not used, and no value is assigned-an error is returned. If a value is assigned, js treats it as a global variable and does not report an error. (Not recommended for the latter)
C. Data Type
Typeof () Operator: one-dimensional operator used to detect data types, and the returned result is always a string.
The isNaN () function is used to check whether the parameter is a non-numeric value.
1. Initial type
A. undefined -- no value is assigned after the variable is created. The default value is undefined.
B. null -- nothing, only one placeholder
C. number: integer and floating point type. It supports binary, octal, decimal, and hexadecimal. It is output in decimal format. Special Value
1. II. octal: starts with 0
2. hexadecimal: starting with 0x
3. Special values:
Maximum: Number. MAX_VALUE
Min: Number. MIN_VALUE
Infinity: Infinity
Infinitely small:-Infinity
D. string -- a string enclosed by a single double quotation mark. It also contains some special characters.
1. Single double quotes have the same efficiency (different from PHP)
2. It can only appear in pairs and cannot be used in combination.
3. can nest var a = "a '11 '";
4. Special characters
\ N line feed
\ T Tab
\ B space
\ R line feed
\ 'Single quotes
\ "Double quotation marks
\ Slash
2. Reference Type
| Type |
Value |
Typeof Return Value |
| Undefined |
Undefined |
Undefined |
| Null |
Null |
Object |
| Boolean |
True, false |
Bollean |
| String |
Value between single and double quotes, special symbol |
String |
At the beginning, there are deficiencies or error messages in writing at the front-end. I hope you can give some advice and make progress together.