JS Self-Study Encyclopedia

Source: Internet
Author: User
Tags script tag switch case try catch

JS is executed from the top down.

Console.log (); Output statement
Console.warn (); Error prompt statement yellow triangle exclamation mark
Console.error (); Error warning red circle X
alert (); pop-up window
document.write (); file printout such as Web pages have time countdown next second need to print
Document.getelmentbyid (); Specify an ID to change it style JS Use this statement when you want to use an ID
Decument.getelementsbytagnanme (); Returns an Array object
Decument.getelementsbyclassname (); Returns an Array object

Decument.getelementsbyclassname (); Is the new method of it and decument.getelementstagname (); What's the difference?
-------

JS no-like Background-color JS is backgroundcolor
Variable name can be kanji but IE browser does not support
JS in addition to nested "" "double quotes and single quotes no difference

The global variable in JS is
var num=10;
function fn () {

num = 20; This is all the variables.
}
var a=b=c=9; BC belongs to global variables
External is the global variable can be used
For example, in a function where Var is not defined, the global variable
A local variable is a variable declared inside a function.

Event three elements: syntax format
Event source. Event =function () {event handler}

Event three-Factor mouse event Summary

General Event Event Browser support description
OnClick ie3| n2| O3 Mouse Click event, multi-use in the scope of an object control mouse click
OnDblClick ie4| n4| O Mouse Double-click event
OnMouseDown ie4| n4| O the button on the mouse is pressed
OnMouseUp ie4| n4| O events fired when the mouse is pressed and released
onmouseover ie3| n2| O3 event that is triggered when the mouse moves over the range of an object
OnMouseMove ie4| n4| O events triggered when the mouse moves
onmouseout ie4| n3| O3 events that are triggered when the mouse leaves an object range
onkeypress ie4| n4| O event that is triggered when a key on the keyboard is pressed and released. [Note: There must be a focused object within the page]
OnKeyDown ie4| n4| O event triggered when a key on the keyboard is pressed [Note: There must be a focused object in the page]
OnKeyUp ie4| n4| O event triggered when a key on the keyboard is pressed to release [note: There must be a focused object in the page]


Hidden box:
Display:none the position of a hidden account;
Visibility:hidden; hide Occupy position
Overflow:hidden; hide out of place
For example: Event source. style.display:none;

Entry function: placed in the upper part of the script tag is below the body, such as the carousel is placed in the inside because the page load the structure and then load the style of the General page load structure and links can point the carousel map load after the click to move
Window.onload=function () {
Put JS here.
}


JS in typeof detection data type
var txt= "Ah";
Console.log (typeof txt); String

Turn character type: String ();
var num=10;
Console.log (String (num));

Data type go to Boolean
1.!!
2.Boolean ();

The law of "0" +1=01 character type plus integer type

020 0 begins with octal 0 multiplied by 8 by 0 times 2 by 8, so 020 is 16
0x starting with 16 binary

Convert value:
1.Number ();
2.-*/
var a= "20";
var b=a-10;
Console.log (b);

parseint (value, binary);
Console.log (parseint (10,2))//10 binary 4 10*2 0 times 1*2 1-square
Console.log (Paeseint (10.11))//Rounding is 10
Console.log (parseint ("20"));//20

<script type= "Text/javascript" >
The parsefloat () function resolves a string and returns a floating-point number
document.write (parsefloat ("10"))
document.write (parsefloat ("10.00"))
document.write (parsefloat ("10.33"))
document.write (Parsefloat ("34 45 66"))
document.write (parsefloat ("60"))
document.write (parsefloat ("Years"))
document.write (parsefloat ("He was 40"))


JS feature variable Promotion: If the function is declared inside the function, the declaration is lifted to the top of the function, only the variable is lifted, and no value is assigned.
function Fun () {
Console.log (num);
var num=10;
}
Equivalent to:
Funion Fun () {
var num;
Console.log (num);
num=20;
}

function fn (A, b);
Console.log (fn.length); The number of formal parameters is AB
Console.log (arguments.length); The number of arguments is the number of calls

Empty type:
NULL: The variable cannot be null if you need to manually set the object's occupation or reference to be lifted
Undefined: the definition is not assigned after the value such as Var obj;console.log (obj);

Congruent = = =
equals = =
Difference: Congruent comparison value and type equals comparison value

The In keyword is most commonly used for the in
var obj={
Name: "I Am Me,"
Age:18
};
For (var k in obj) {
Console.log (typeof K);
}//output to String type
The key for the object that determines the variable

In Method 2:
Determines whether a property exists in an object
var obj={
Name: "I Am Me,"
Age:18
};
var a= "name" in Obj;//name what type to learn such as string to double quotation marks or single quotation marks
Console.log (a);
Note: When the In keyword operates an array, it is determined whether the index exists
So var arr=[1,2,3,4];
Console.log ("0" in arr); output is true
The index is the array from the 0-point (self-understanding) is 1234 The corresponding index is 0123

The array also has a fixed way to find the specified number if no return-1
var arr=[1,2,3,4];
Console.log (Arr.indexof (3)); return 2

Create a Time object
var a=new date (); The//date type is specifically used to convert the time format to a string there are a variety of small ways to look at JS so the Redbook or in my blog garden will be the small way to organize
Console.log (a);//output is time is not a pure number in English tell

Object dynamic refers to adding a new property or method to an object after it is created
var obj={
Name: "Andy Lau",
Age:50
};
obj.gender= "Male";
Obj.sayhello=function () {
Console.log ("I want to die for You");
}
Obj.sayhello ();
Obj.sayhello=function () {method}
OBJ.XXX=XXX---
----1. If XXX exists it is modified
----2. Add attributes if XXX is not present
Get property values for an object: Object name [property name]


Implicit conversions: Go to String type
For example Obj[0]=function () {Console.log ("I added succeeded")}
Values in [] are converted to strings

Delete operation
The Delete keyword can delete object properties and variables that do not use Var

Delete. Variable name or object property
If the deleted object does not exist returns true if the delete succeeds False/true if the deleted property returns true in the prototype


Expression 1| | Expression 2
If 1 is true return 1
If 1 is false return 2
Only the truth is true, the rest is false.

Expression 1&& Expression 2
If expression 1 is false, return the value of expression 1 directly
If expression 1 is true, determine if 2 is true, if true, return expression 2 if False
The only fake fake is fake, the rest are real.

function declaration:
function A () {
function body
}
function expression:
var a=function b () {//b is the function name
The function name may not be written but it is written only within the function call
}

To create a new function:
var a=new function () {

}

Dom Operation: Adding and deleting changes
Add: 1.decument.createelment
2.oppendChild
Delete: 1.removeChild

Change: 1.style
2.id
3.className
4.innerHTML
Check:
1.getElementById
2.getElementsByTogName
3.getElementsByClassName

Exception Capture statement: Feature-Once an exception occurs, the code will not perform the exception that you want to do
Try Catch finally

try{the code that may appear to be abnormal,
Throw "Your code is faulty";//Receive throw exception message
ErrMsg: "Write the error message here";
errcode:-1;//here write the return value of the error code
}
Catch X (parameter) {processing code after an exception occurred}
X () {}
Finally{will be executed regardless of whether the error occurs
Freeing resources in node. js
}

Grammatical anomalies cannot be captured such as a++++++++;

The object-oriented understanding is: To solve the problem of the targeted objects, such as washing clothes to find a girlfriend washing machine wash

What is an object? All things are objects
What is an object feature? Information used to describe an object such as a person's name age
What is the behavior of an object? Describes the behavior of an object such as a person walking and eating

What is an object in JS species? A combination of key-value pairs is an object

The real-life characteristics of the example above are the attributes of JS.
Behavior is the method

Prompt ();//There is an input box in the dialog box that can be entered
alert ();//You can't cancel it in the Talk box.
Confirm ();//A conversation box can be canceled.

true: Except for 0 number "something" object (any object) is True
false:0 "" Undefined null to False
If the value in () is forcibly converted to a Boolean type when judged

var a= "hello\" aaa\ ""; Print output Hello "AAA"
Turn to String type:
Variable + "" Variable + "any one string" toString

You can go to the following string:
var num=1111;
var bool=true;
Console.log (typeof (String (Boolean)));
Console.log (typeof (Num.tostring));

Number conversion:
var a=number ("222");
var b=number (18.33);

Boolean conversions:
var A=boolean ("222");
var b=boolean (18.33);

parseint (variable); rounding
var A=aaa3.14ss; take Out is 3.14
parsefloat (variable); take floating point

For loop inside loop control inline loop control column

Break immediately stop this loop is not executing
Continue jump out of this cycle into the next loop

The value is fixed with a while statement
To judge a specific value with a switch case
Other uses if if else if else else ....
Do and at least once

var arr=[1,2,3];
Console.log (arr[1]);
Assigning a value to an index
arr=["Zhang Fei"];
Arr=["Zhang Fei 1"];

Function name () {
a carrier; return;
The value after return is the return value
}

If the function name is the same, subsequent functions overwrite the previous function

The function is recursion, it's calling itself.
FN ();
function fn () {
Alert (111);
FN ()
}
Recursive note: Recursion is necessary to have a bounce condition or a dead loop.
var I=1;
FN ();
function fn () {
Alert (111);
i++;
if (i>10) {
Return
}
FN ();
}

Using recursion to write 1-100 and
Alert (A (100));
function A (n) {
if (n<1) {
return 0;
}
Return N+a (n-1);
}

callback function: Call function as parameter and use number call other function call callback function
fn (test);
function fn (demo) {
Demo ();
}
function Test () {
Console.log ("I am the function being tested");
}
When to use a callback function:
It is generally a rule that defines a rule that is passed only by using a function or callback function to implement

Console.log (FN (10,5,test1));
function fn (Num1,num2,demo) {
Reurm demo (num1,num2);
}
function Test1 (A, b) {
Returm a+b;
}
function Test1 (A, b) {
Returm A-B;
}

The literal of the object:
var aaaa={something};

Create a div and set a style and add it to the body tag

Use of JSON:
JS features describe JS data used to store things
var json={
A:12,b:5,c=3
}
alert (JSON.A);//can also be written as alert (json[' a '); JS [] can replace everything.
The angle of the JSON is not a number, it's a letter

JSON does not have length, so how to use it in a bad way.
Use for in
for (var i in JSON) {
Alert (' +i+ ' thing: ' +json[i]);
}
Can also be manipulated like a variable

Compatible universal use if else to handle
The inline style is the CSS code written in the HTML tag style can only manipulate the inline style
Currentstyle get non-inline style compatible with IE only
Then use if Else
Other browsers compatible with getComputedStyle

JS Self-Study Encyclopedia

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.