JavaScript Learning Notes collation (overview, variables, data type Introduction) _ Basics

Source: Internet
Author: User
Tags modifier numeric value reserved

A. Overview
1. Output tool:

document.write ()---can be html

Alert ()---string

Prompt (Text,defaulttext)
Text---optional. The plain text to display in the dialog box rather than the HTML-formatted text.
DefaultText---Optional. The default input text.

Placement of 2.js

A. Can be placed in any position of HTML

B. But he is a whole, interacting with each other

C. Location of hyperlinks and redirects

<a href= "Javascript:alert ();" ></a>
<form action= "Javascript:alert ();" ></form>
<div onclick= "alert ()" ></div>

********ie is feasible and does not recommend the use of ********
<div id= " One "></div>
<script for=" one "event=" onclick ">
alert ();
</script>

D. Calling external JavaScript files
<script src= "" ></script>
1. No code can appear inside the JS tag of the call
2.js script cannot appear in <script> label
3. It's still interconnected and influential.
3. Note
A. For old browsers
<!---->
* If the old browser does not recognize JS, comment
B. Real notes
In-line comments//
Block Comment/*/

B. Variables

1. Naming conventions
A. Strict case sensitivity
B. The name of the variable must begin with a letter or _ or $, and the remainder 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 conventions
The method of naming the hump: getElementById
Initial Capital: Object
Meaningful naming: Name, age
2. Variable: A variable that can store data
A. How variables are created (* * must be decorated with the var keyword * *)
Declare first, then assign value: Var a;a=3;
Declare assignment at the same time: 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 an existing variable
1. If you change the quantity without assigning a value, the value of the variable does not change
var a=1;var A; Results a=1;
2. If you change the quantity and assign a value, the value of the variable is changed to the new variable value
var a=1;a=3; Results a=3;
3. Do not use the keyword var modifier variable
A;alert (a); Error
A=1;alert (a) Results: 1
If you do not use the Var modifier, and no assignment---error; There are assignments, JS as a global variable, no error. (The latter is not recommended)

C. Data types

typeof () Operator: A unary operator used to detect a data type, and the result returned is always a string
The isNaN () function checks whether the argument is a Non-numeric value
1. Initial type
a.undefined--variable is not assigned after creation, and its default value is undefined
b.null--Nothing, only one placeholder
c.number--shaping, floating-point type, support two or eight, 16 or 16, all are in decimal output; special value
1. Two or eight binary: with 0 opening
2.16 in: Start with 0x
3. Special values:
Max: Number.MAX_VALUE
Min: Number.min_value
Infinity: Infinity
Infinitely small:-infinity
d.string--a string enclosed in single double quotes, and also includes special characters
1. Single double quotes are as efficient (unlike PHP)
2. Can only appear in pairs, can not cross the use of each other
3. Can be nested with each other var a= "A ' 11 '";
4. Special characters
\ n Line Change
\ t tab
\b Space
\ r Line Wrap
\ ' Single quotes
\ "Double Quotes
\ Slash Slash
2. Reference type

Type Value typeof return value
Undefined Undefined Undefined
Null Null Object
Boolean Ture,false Bollean
String The value between single and double quotes, special symbols String

First into the front, write things have inadequate or wrong message also hope that the road to the great God guidance, mutual encouragement and progress.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.