Javascript Centralized Knowledge Reserve

Source: Internet
Author: User

This article summarizes the commonly used knowledge in JS, some almost do not use, or belong to the design flaw, but must know, these are my development summary, if there is incorrect place, please point out.

Personal code habits sharing: Naming as far as possible semantic but more special, this will avoid naming conflicts, even if the global local variables will belong to different domains and do not use the same name, a little longer okay, not very English how to do? Pinyin!

A. Variable

1.) in non-strict mode, global variables can be used directly without Var, but this is not good, will cause ambiguity, reading will be difficult. So the formal wording is in advance declaration.

2.) There is a concept called variable promotion, within the function, all variables will be promoted to the upper part of the function body declaration.

function Upvar () {console.log (x); var x = 0;} Upvar ();//print undefined

Variable declaration after printing, even in strict mode will not error, because the JS mechanism to advance the variable declaration to the first line of the function body, but not assigned value, so the above function is equivalent to:

function Upvar () {var x;console.log (x); x = 0;} Upvar ();//print undefined

So what if the global variable has the same name as a local variable inside the function? The result is the same. The function first scans the inner function.

var a = 2;function Samenamea () {Console.log (a) var a = 3;} Samenamea ();//print undefined

  

Variable use must be declared in advance and must be assigned in advance before use. So in my opinion, unless the brain cramps, I will not write this code. Belong to remember the concept can.

3.) This point

At the global scope, this is a pointer to the window, which means you can use this. The variable calls the global variable, this. function calls the global function.

Within the object, point to the current object.

Within the event, point to the event Dom.

Two. Data type

1.) JS has v basic type, a reference type

Base type: String,boolean,number,undefind,null

Reference type: Object (date,array,reg,function)

Basic Package Type:

Monomer built-in objects:

The base type is a simple value, what you see is what you get, the reference type is a complex type, and its value is calculated.

2.) type built-in function

String

Wait More ...

Javascript Centralized Knowledge Reserve

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.