The 21 basics of JavaScript

  • 2020-03-30 02:12:57
  • OfStack

1.JavaScript case sensitive;
2. If var is not written, global variables are declared; Any function that is not a method is a global variable, and the "this" in it refers to the window;
3.% operator, find the remainder, keep the integer, y=5; X = y % 2; X = 1;
4. If you need to concatenate two or more string variables, use the + operator to distinguish it from PHP.
5. Three-item operation: greeting=(visitor== "PRES")?" Dear President ":" Dear ".
6. IndexOf () method, counting from 0, the space is also counted as a bit;
Math.floor() takes an integer down, returns a value less than or equal to that number, math.floor (-5.9), returns -6;
8. Always use the var command when declaring variables inside a function. If not, you're actually declaring a global variable!
9. When writing the demo, be sure to write JS at the bottom to prevent the expected effect of JS code running because the HTML elements are not loaded (JS is an interpreted language, which explains while loading, and can only be acquired and operated after the target object is loaded into the DOM tree);
A closure is simply a nesting of functions. An inner function can use all the variables of an outer function, even if the outer function has been executed.
The value of the checkbox is check, not true; Undefined, not false;
Typeof (flag)=== "undefined";
13.JS functions can access global variables internally, which is different from PHP.
This in a function always points to the caller. Is the method's function this points to the object itself (note the closure problem in the method, this points to the window);
15. Method to destroy variables: obj = null; The delete obj.
16. When directly determined, the following is converted to false: undefined,null,0,-0,NaN, ""; All other values, including objects and arrays, are converted to true;
17. Boolean contains a toString() method that returns true or false;
18. It can be said that javascript has only six data types, Numbers, strings, Boolean values, null, undefined and objects;
19. There is no block-level scope in javascript, instead it is a function scope (see rhino book P57, 6th edition);
20. Javascript's declarative advance feature: all variables declared in a function are advanced to the top of the function (see rhino P58);
JS function execution is asynchronous, to pay attention to the value of the problem

Related articles: