JavaScript base (ii) Data Types

javascript variable number of issues

  Definition and is not defined and undefined

<Script type = "text / JavaScript"> 
    A = 40 ; 
    the console.log (A); // may output a = 40, but not recommended, preferably with A = 40 var; 
    the console.log (B); // Not defiend IS B 
    var C; 
    the console.log (C); // A undefiend 
</ Script>

  Two variable values ​​exchanged

<Script type = "text / JavaScript">
     // do not use a third variable, the value of two variables exchange 
    var A = 50 ;
     var B = 40 ; 
    A = A + B; // A = 90; B = 40 ; 
    B = A - B; // A = 90; B = 50; 
    A = A - B; // A = 40; B = 50; 
</ Script>

js is weakly typed language

  • We will go to infer what type of value.
    •   js typeof name provides a method to determine what type
  • For boolean data in the true and false, 0 and 1 with involvement operation. 
    •   Digital Plus string: convert a number to a string
    •   Digital Plus boolean values: true is converted to 1, false converted to 0
    •   + Boolean string: String Boolean value to true or false
    •   Boolean Boolean +: Boolean value 0 or the value 1
  • Any value can be converted boolean
    •   Empty string, 0 and NaN, null, undefined is false, others are to true .
  • Numerical problems
    •   Infintiy and -Infintiy: infinite and infinitesimal
    •   NaN: non-numeric (Not a Number)
    •   NaN is not equal to any value, including NaN
    •   isNaN () can not be converted into any value will return true 
      •   isNaN(“abc”);//true
      •   isNaN("1");//false

js data type conversion

  • toString (); null and undefined not toString () method, can be used String ();
  • String();//String(null);
  • Number (); // for a character string with a return NaN, the following code
  • parseInt () and parseFloat (); // For the first character string return NaN, otherwise it returns the number of characters before

  The Code

// Note 
// the parseInt ( "value", "band"); 
the parseInt ( "12.3abc"); // return 12 is 
the parseInt ( "abc12.3"); // Returns NaN3 
the parseInt ( ""); // return NaN 
Number The ( ""); // returns 0 
Number The ( "1223a"); // returns NaN

For operators

  1. In addition to 0, return to Infinity; 0 modulo time to return NaN
  2. ++ a; // a = a + 1; expression returns the value of a
  3. a ++; // return value of a first expression in the calculation.

For js array

  • Ordered list
  • Any type
  • Variable array size

  

 

  

 

Guess you like

Origin www.cnblogs.com/yuan1994/p/11183898.html