Learn JavaScript or think that learning is not solid "summary"

Source: Internet
Author: User
Tags logical operators string to number

Today, I write this article, because of being asked questions, a lot of things although have been learned to read, but there is no real understanding??? In order to learn better, I wrote this summary, of course, this article is only a document. Just a tutoring role.

Some people say JavaScript is difficult, but this is H5 development of the basic language, let us cross the threshold together ....

JavaScript-language: Ecmajavascript (Syntax) DOM and BOM composition
Web Development Program Execution Flow: HTTP request resolution URL path Request server

HTTP Hypertext Transfer Protocol

Two JavaScript comment syntax:///* */
Too many JavaScript annotations reduce the speed and speed of javascript execution, so when you publish your website, you should remove the extra
Release.

First, the data type:
1. Any operation involving Nan (for example, NAN/10) will return Nan
2. Nan is not equal to any value, including Nan itself. Once it appears in the program: NaN. Then there must be an illegal operation.

A null value represents an empty object pointer, so you return "object" when you use the typeof operator to detect null values
typeof (NULL)//object

Alert (typeof (null))//object
Alert (typeof NaN)//number
Alert (number (TRUE)) True indicates that 1 false means 0
Alert (parseint ("123.321blue"))//Convert to Blue/nan that cannot be converted
var a = 11,b = ' 22 ';
var C = a + B;
Console.log (c)//33 when one is a numeric type one is the string JS engine will default to non-algorithmic calculations, using the operator "+" This feature, it is convenient to convert number to string

var a = 22,b = ' 11 ';
var C = A-B;
Console.log (c)//11 and "+" in contrast, here the B by default to digital type 11 for the algorithm calculation, using this feature is convenient to convert a string to number
var i = 1; j = ++i;
Console.log (j);


Second, the expression is by the constant, variable, function and so on through the way of computing logic to join together.
Operators are commonly used to:
The algorithm operator is generally +-*/% (film, used to take the remainder)
comparison operator = = = <= >= is generally used to judge
logical operators! Inverse && co-existence relationship two is true to TRUE | | One for true is true
Ternary operator? Is the judging condition: false eg:1<2 before true? Alert (1+ "less than 2"): Alert (1+ "
Greater than 2 ")
Void is an operator with no return value. Usage format: void (0) The most common form of a href= "#" will refresh the page as a whole
href= "javascript:void (0)" will not
The comma operator.
Declare the variable with a var, comma connection ', ' recommended to write so.

Conditional statements:
If: a judgment statement, often used, allows the JavaScript program to selectively execute statements.

switch when only one expression is judged, switch is used first.

The For Loop statement is often used to increment and decrement.

return value.

Third, function: Improve the reusability of code (reusability)
function needs to be called to execute.
The function has scope. Outside the function is a global variable that can be used anywhere. Anyway, local variables can only be executed in the function.

Math object:
Math.random () returns the random number between 0-1
Random numbers define random values: Math.floor (Math.random () * (maximum-minimum +1) + minimum)

String: Types of strings that handle text
Declares a string
. CharAt () returns the character that is located
. charCodeAt () returns the Unicode encoding where
String.fromCharCode () returns Unicode encoding
. Search () returns the location that matches the parameter
string replaced by. Replace ()
. substring () Extract the character parameter between two subscripts cannot be a negative number similar to slice ()
. substr () The first one is to start subscript two for length
The. Match () finds the specified value within the string index. Split () splits the array string from the specified place
. Concat () connect two or more strings

var str=new String (' Lijiayang ');
Alert (Str.search (' Jia '))
Alert (str.substring (4))

four, array: Key value pair
Add data
var a=[];
a[0]= ' 1 ';
a[1]= ' 2 ';
You can also use A.push (' 3 ')
Remove Delete arr[0]
Pop () Delete last element
Join () Replace delimiter
Reverse () Element order reversed
Sort () element for sorting
Concat () Merging arrays
Slice () intercept array
Splice () Insert, delete, replace
Unshift () Adding elements to the head
Shift () deletes the first element

var a=[];
a[0]= ' 1231 ';
a[1]= ' 213 ';
Console.log (a)

For/in loops used in loop arrays and JSON

Five, dom:html all content in a document is a node (element tree)
Dom node Relationship: ancestor (parent) child (children) sibling (sibling
1, parentnode     Get the parent node of the node
2, childnodes     Get the node's child node array     
3, firstchild     Get the first child node of the node     
4, lastchild     Get the last child node of the node     
5, nextsibling     Gets the next sibling element of the node     
6, PreviousSibling      Gets the previous sibling element of the node
7, children gets all the child element nodes
AppendChild () Creates a new node
createelement ()//creates a specific element
createTextNode ()//Create a text node
appendchild () Add
removechild () Remove
ReplaceChild () Replace
InsertBefore () insert The
CloneNode () method creates an exact copy of the specified node
CreateAttribute () creates a new Attr node

OffsetParent A read-only property returns the nearest parent of the current element with a positional property offsetleft returns the x of the element sitting
The offsettop returns the y-coordinate of the element scrollheight the past scroll height
ScrollLeft Sets or gets the distance between the left side of the visual window
ScrollTop Sets or gets the distance between the top of the visual window
Bom:
Six, window: Represents the browser window
A global variable is a property of a Window object.
A global function is a method of a Window object. Window Time Function:
SetInterval () Timer
SetTimeout () Disposable Timer
Clearinteval () Clear Timer
Cleartimeout () Clear Disposable timer

Seven, system pop-up box:
Alert (), confirm (), prompt ()
Location object:
Location.hostname returns the host name of the current URL.
Location.pathname returns the path portion of the current URL.
Location.protocol returns the protocol for the current URL.
Location.href returns the full URL.


Eight, the event flow:
Event bubbling:
Propagating upward from the most specific element is called event bubbling.
Event Capture:
Flow from document documents to most specific elements
Event delegate:
Assigning the parent element's events to child elements
Event Bindings:
Add an event to an element
Event object:
The event object represents the state of events, usually with functions using the state of the keyboard key, the position of the mouse, the state of the mouse button

Nine, form verification, login information will generally be used to verify:
Add a slash before and after the string with/javascript/^ means start $ end

Learning JavaScript or not learning a solid "summary"

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.