Python JavaScript day1

JavaScript (one of the browsers programming language)
1. form of
  1. As with CSS, you can import the file to use
  2 can also be written at the beginning of a <script> </ script> includes up
  3. Better yet, put rearmost body, otherwise if placed in front of and JavaScript and very time-consuming operation, it will make
    the page has been loaded but not see what body of
  4. there are a lot of microcontrollers with similar habits, remember to finish a sentence plus;
2 variables
  var a = 123; the local variable
  a = 123; global variables
  PS: every time can be written with the variables are local variables, global variables when needed and then change over to avoid mistakes
3. data type
   1. digital: the JavaScript does not distinguish between floating point and integer values, JavaScript, all figures are represented by floating-point number
    converter:
      the parseInt () insert a value into a digital, unsuccessful NaN3
      parseFloat () converts into a floating point value, unsuccessful NaN the
    special value:
      NaN, non-digital, may be used isNaN (num) to determine the
      infinity, infinity can be used isFinite (num) to determine
   2. string:
    String is an array of characters, but in JavaScript strings are immutable: You can access the string anywhere in the text, but JavaScript does not provide a way to modify the contents of a string known.

. 1              obj.length length
 2              obj.trim () remove the white space
 . 3              obj.trimLeft ()
 . 4              obj.trimRight)
 . 5              obj.charAt (n) Returns a string of n characters
 . 6              obj.concat (value, .. .) splicing
 . 7              obj.indexOf (the substring, Start) returns the sequence position (front to back)
 . 8              obj.lastIndexOf (the substring, Start) returns the sequence position (back to front)
 . 9              obj.substring ( from , to) in accordance with Gets the index sequence (sense and sliced almost)
 10              obj.slice (Start, End) sections
 11             obj.toLowerCase () uppercase
 12 is              obj.toUpperCase () lower case
 13 is              obj.split (DELIMITER, limit) divided
 14              obj.search (regexp) scratch match, return to the first position matching is successful (g invalid)
 15              obj.match (regexp) global search, if there is regular in g denotes find all, or else only to find the first one.
16              obj.replace (regexp, Replacement) Alternatively, the regular replacement of all there g, or replace only the first match,
 17                                                   $ numbers: n-th matching set of content;
 18                                                   $ & : the contents of the current match;
 19                                                   $ `: it is located in the left side of text matching substring;
 20                                                  $ ' : Matching substring to the right of the text 
21                                                   $$: Direct amount $ symbol
Common features

 

  3. Boolean:
    a lowercase: A = to true

    == equal
    = not equal!
    === types are equal when the ratio
    when the ratio of type not equal ==!
    || or
    && and

For example: A = ' 123 ' B = 123 ;
A == B is true, only the size of the comparison value, irrespective of the type
A === B is false, and the value must be the same type

  4. Array:
    similar Python list, may be used a = []; to create the array

1  the size of the array obj.length
 2  obj.push (ELE) tails added element
 . 3  obj.pop () Gets a tail element
 . 4  obj.unshift (ELE) head insertion element
 . 5  obj.shift () header removing element
 6  obj.splice (start, deleteCount, value, ...) to insert, delete or replace elements of the array
 . 7  obj.splice (n-0, val) designated position of the insertion element, n representative of the position, val representative of the inserted element is fixed 0
 . 8 obj.splice (n-,. 1 alternative element, val) designated position
 . 9 obj.splice (n-,. 1 ) to delete the specified position of the element
 10  obj.slice () sections
 . 11  obj.reverse () inverted
 12 is  obj.join (On Sep) the array elements are connected together to construct a string
 13 is  obj.concat (Val, ..) connected to the array
 14 obj.sort () to sort the array elements
Common features:

4. Other:
   Escape:

            encodeURL (url); behind the URL of the Chinese, brackets or the like into the browser can recognize things
            decodeURL(url);
            encodeURIComponent (); everything inside the URL conversion, including // : like
            decodeURLComponent();
            Escape (); string escape
            unescape (); decoding

  the eval:
5. The time to process
  a = new Date; directly create a time zone for the present line, can be used to get the desired value is obtained, with the setting value set to
6. The regular expression:
7. statement:
   1.If

    an if (condition) {}
    the else  an if (condition) {}
    the else {}

  2.switch

    switch(name){
    case '1': age = 123; break ;
    case '1': age = 456; break ;
    default : age = 789;
    }

  3. Cycle:
    1.while (condition) {}
    2.For (var I = 0; I <10; I ++) {} The conditional loop (not handle dictionary)
    3.for (in li I var) {} The li the index to what extraction (dictionary can be processed, is taken out as KEY)
  4. exception handling:

    try{}
    catch (var) {} If an exception is thrown try to execute the statement can be entered variables var
    the finally {} performed anyway

    new new Error the throw ( ' xxx ' ) initiative to create an error

8. Function:
   Common Function:
    function F1 () {}
  anonymous function:
    the setInterval (function () {Alert (. 1)}, 1000);
   self-executing function:
    (function (Arg) {Alert (Arg)}) (123) function itself will perform the function
9. scope:
  1. there is no block-level scope, but let
    example:

. 1  the while (. 1 ) {
 2 the let let1 = 2 ;
 . 3 var var1 = 2 ;
 . 4  }
 . 5 Alert (let1); // inaccessible
 . 6 Alert (var1); // can access

  2. Using function scope: Variables can not access the functions inside the outer function

function main(){var a = 'a'}
main();
console.log (A) // error

  3. The scope chain

xo = 'one';
function f1() {
var xo = 'two';
function f2() {
var xo = 'three'
console.log(xo);
}
f2();
}
f1 ();

Output three

  Execution console.log (xo); we'll find out when one layer at xo, if there is output, not to continue to find out
4. scope chain before the implementation has been created

  Example 1

xo = 'one';
function f1() {
var xo = 'two';
function f2() {
console.log(xo);
}
return f2;
}
var RET = // f1 ();
 // RET (); 
Although there is no call to f1, but the scope has been created, and the scope f1 created in var xo; but the value is undefined,
when executed, creates var f1 xo = 'two', var ret = f1 {}, and returns f1 f2, f2 of ox will often need to find outside from the inside, one found on var xo = 'two', so the value ret is two.

  Example 2

xo = 'one';
function f1() {
var xo = 'two';
function f2() {
console.log(xo);
}
XO = ' Three ' ; // Here is reassigned var xo, not create global variables xo, that has been created var xo above a
 return F2;
}
was quite = f1 ();
right();
Scope layer by layer, so that the value of three ret

  Example 3

<script>
xo = 'one';
function f1() {
console.log(xo);
}
function f2() {
var xo = 'two';
return f1;
}
was quite = f2 ();
right();
</script>

This is equivalent to ret is f1, to find out from the start f1 scope, it is one ret

 

Guess you like

Origin www.cnblogs.com/otome/p/12588542.html