21 Basic knowledge points in JavaScript-Basic Knowledge

Source: Internet
Author: User
This article mainly introduces 21 Basic knowledge points of JavaScript. For more information, see section 1. JavaScript case sensitivity;
2. If the declared variable does not write var, it declares the global variable. Any function that is not a method is a global variable, and this in it points to the window;
3.% operator, evaluate the remainder, retain the integer, y = 5; x = y % 2; then x = 1;
4. to connect two or more string variables, use the + operator to distinguish it from php;
5. maxcompute: greeting = (visitor = "PRES ")?" Dear President ":" Dear ";
6. The indexOf () method is counted from 0, and a space is also counted as one;
7. Take Math. floor () down to an integer. The returned value is less than or equal to this number. Math. floor (-5.9), and-6 is returned;
8. When declaring variables in a function, you must use the var command. If you don't need it, you actually declare a global variable!
9. when writing a demo, you must write JavaScript code to the bottom to prevent the JS Code from running out of expectation because html elements are not loaded (JS is an interpreted language, loading and interpreting, the object can be obtained and operated only after it is loaded to the DOM tree );
10. closure: the closure is actually a function nesting. The inner function can use all the variables of the outer function, even if the outer function has been executed (so the closure may have performance problems, the outer variable remains in the memory after the outer function is called );
11. the checkbox value is check, not true; the canceled value is undefined, not false;
12. typeof (flag) = "undefined" is used to determine whether the variable is undefined ";
13. JS functions can access global variables (or function external variables), which is different from PHP;
14. this in a function always points to the caller, or it can be said: not a method function, this points to window; it is a method function. this points to the object itself (pay attention to the closure problem in the method, this indicates the window );
15. Methods for destroying variables: obj = null; delete obj;
16. when you directly judge, the following values are converted to false: undefined, null, 0,-0, NaN, "" (empty string); all other values, both objects and arrays are converted to true;
17. The Boolean value contains a toString () method, which can return a string of true or false;
18. javascript has only six data types: Numbers, strings, Boolean values, null, undefined, and objects;
19. There is no block-level scope in javascript, And it is replaced by the function scope (see section 6 P57 of the rhino book );
20. Early features of javascript Declaration: all variables declared in the function are advanced to the top of the function (see the sixth version of the rhino P58 );
21. JS functions are executed asynchronously. Pay attention to the value.
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.