21 Basic knowledge points for JavaScript

Source: Internet
Author: User
Tags closure

This article mainly introduces the JavaScript 21 basic knowledge of the relevant data, the need for friends can refer to the

1.JavaScript case sensitive;

2. Declare a variable if you do not write Var, the global variable is declared; any function that is not a method is a global variable, all of which points to window;

3.% operator, to find the remainder, to retain integers, y=5;x=y%2; then x=1;

4. If you want to connect two or more string variables, use the + operator, different from PHP;

5. Three mesh operation: greeting= (visitor== "PRES")? " Dear President ":" Dear ";

6.indexOf () method, from 0, the space is counted as one;

7.math.floor () takes the integer down, returns a value less than or equal to the number, Math.floor (-5.9), returns-6;

8. When declaring variables inside a function, be sure to use the var command. If not, you actually declare a global variable!

9. Write demo, be sure to write JS to the bottom, to prevent because the HTML element does not load, resulting in JS code can not run out of the expected effect (JS is interpreted language, edge loading edge interpretation, only the target object is loaded into the DOM tree can be acquired and manipulated);

10. Closure meaning: Closure is actually a function of nesting, the inner function can use all the variables of the outer function, even if the outer function has been completed (so the closure will have performance problems, the outer layer of the function call after the end of the variable is still in memory);

The value of the 11.checkbox tick is check, not true; the cancellation value is undefined, not false;

12. The judgement variable is not defined with typeof (flag) = = "undefined";

The 13.JS function can access global variables (or function external variables), which is different from PHP;

14. This in the function always points to the caller, or it can be said that the method is not a function, this points to window; This is the function of the method that points to the object itself (note the closure problem in the method, this is pointing to window);

15. Methods of destroying variables: obj = null; Delete obj;

16. Direct judgment, the following will be converted to False:undefined,null,0,-0,nan, "" (empty string); all other values, including objects, and arrays are converted to true;

17. A Boolean value contains a ToString () method that returns a string of true or false;

18. JavaScript can be said to have only 6 types of data, numbers, strings, Boolean values, null, undefined and objects;

There is no block-level scope in 19.javascript, and instead is a function scope (see Rhinoceros Book version sixth P57);

20.javascript declaration advance feature: all variables declared in a function are advanced to the top of the function (see Rhino Book, version sixth P58);

21.JS function execution is asynchronous, pay attention to the problem of value

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.