Home  >  Article  >  Web Front-end  >  JavaScript study notes organization (overview, introduction to variables, data types)_Basic knowledge

JavaScript study notes organization (overview, introduction to variables, data types)_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 15:35:081338browse

A. Overview
1. Output tool:

document.write()---can be html

alert()---string

prompt(text,defaultText)
text---optional. Plain text (not HTML-formatted text) to be displayed in the dialog box.
defaultText---optional. Default input text.

Placement of 2.js

a. Can be placed anywhere in HTML

b. But they are a whole and influence each other

c. At the location of hyperlinks and redirects

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

********IE下可行,不推荐使用********
<div id="one"></div>
<script for="one" event="onclick">
alert(111);
</script>

d. Call external javascript files
​9be8c280d3dc51bb61988971f6c2aa5c2cacc6d41bbb37262a98f745aa00fbf0
​1. No code can appear in the calling js tag
2. The 3f1c4e4b6b16bbbd69b2ee476dc4f83a tag
cannot appear in the js script. 3. They are still connected and influenced by each other
3. Comment
a. For old browsers
19791207a4e0a22c816ac020ecd8cae0
*If the old browser does not recognize JS, comment
b.Real comment
Inline comments //
Block comments /* */

B. Variables

1. Naming convention
a. Strictly case-sensitive
b. The variable name must start with a letter or _ or $; the remaining part can be any letters, numbers, _, $
c. Cannot use keywords or reserved words to name
Keywords: for, if, try, etc.
Reserved words: byte, char, class, etc.
d. Naming convention
CamelCase nomenclature: getElementById
Capitalize the first letter: Object
Meaningful naming: name, age
2. Variable: A variable that can store data
a. How to create variables (**Must be modified with var keyword**)
Declare first, then assign: var a;a=3;
Declaration assignment is performed at the same time: var a=3;
Declaring multiple variables at one time: 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 you re-declare a variable without assigning a value, the value of the variable will not change
  var a=1;var a; result a=1;
​2. If the variable is re-declared and assigned a value, the value of the variable is changed to the new variable value
  var a=1;a=3; result a=3;
3. Do not modify variables with the keyword var
a;alert(a); error report
a=1;alert(a) result: 1
If there is no var modification and no assignment - an error will be reported; if there is an assignment, js will treat it as a global variable and no error will be reported. (The latter is not recommended)

C. Data type

typeof() operator: a unary operator used to detect data type, and the returned result is always a string
The isNaN() function is used to check whether its argument is a non-numeric value
1. Initial type
a.undefined--The variable is not assigned a value after it is created, and its default value is undefined
b.null--nothing, just a placeholder
c.number--integer, floating point type; supports binary, eight, ten, and hexadecimal, all output in decimal; special value
1. Binary and octal: starting with 0
2. Hexadecimal: starting with 0x
3. Special value:
Maximum: Number.MAX_VALUE
Minimum: Number.MIN_VALUE
                                              Infinitely small: -Infinity
d.string--A string surrounded by single and double quotes, including some special characters
1. The efficiency of single and double quotes is the same (different from PHP)
2. Can only appear in pairs and cannot be used crosswise
3. Can be nested into each other var a="a '11' ";
4. Special characters
  n Line break
  t tab character
  b Space
  r Line break
   Single quotation mark
"Double quotes
  \ slash
2. Reference type

类型 typeof返回值
undefined undefined undefined
null null object
boolean ture,false bollean
string 在单双引号之间的值,特殊符号 string
I am new to the front-end. If there are any deficiencies or wrong information in what I have written, I hope that the experts from all walks of life can give me some advice and encourage us to make progress together.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn