js Lesson summary

A three introduction method

  1, the introduction of internal

<script>

      alert ( "aaa"); // written in the head tag
    </ script>

    <script type="text/javascript">

      alert ( "aaa"); // write in the body tag
    </ script>

    The best writing in a recent body from the inside

  2, the line is introduced

    <p onclink="javascript:alert('hell word');">clickme</p>

  3, the introduction of external

    HTML: <script src="js/style.js"></script>

    JS:  document.write("hell word!")

Second, variable

  var variable name = variable value;

  var to declare variables, variable name can contain letters, numbers, underscores and must begin with a letter or an underscore, strictly case-sensitive name, FirstName and firstName is different.

    // a statement to declare variables

      There are a = 2, b = 4, c = 6;

    // declare variables can span multiple lines

      There are a = 2,

      b = 4,

      c = 6;

    <script>

      There are a = 3;

      a = 5; // variables can be declared without var Again

      document.write (a); // 5, the same name will have to cover the variable name

    </script>

    // hump labeling and underlined Act

      var firstName = 'king'; // small hump

      var FirstName = 'qween'; // large hump

      var first-name = 'ymt'; // underlined Method

  Two types of variables case

  1, alert (a); // when unquoted variable is not defined, the browser will complain, a is not defined a not defined

  2, var a; // when no assignment of a defined, no error will be prompted undefined undefined

    alert(a);

Third, the output

  . 1, <Script>
    Alert ( "AAA"); // Alert warning window pops
    </ script>  

  2、<script>

      document.write ( "hello word!") ; // in HTML can display output content, write labels 

      document.write("<h1>标题一</h1>");    
    </script>

  . 3, <Script>
      the console.log ( "console"); // displayed on the console, F12 ----> select Console
    </ Script>

 Fourth, the conversion

  1, replaced by other types of false must have Boolean type

    var a;    //undefined  ---->   false

    var a="";        //""------->false

    null  ==  undefined 

    "" == 0

  2, other types of conversion into numerical

    var b=undefined;      //undefined ------>  NaN

      b= null;             //null--------->0

      b =true;           //  true ---------->1

      b = flase;         //flase----------->0

      b = '12';          //'12' ---------->12

      b = '3king';      //'3king'--------->NaN

      NaN: number is not a number, can not be compared with any number, including itself. 

Fifth, operators

  1, arithmetic operators

    + Addition                           

    - Subtraction

              * Multiplication                             

       / Division

    % Remainder

    ++ increment, a ++ output and first increment, ++ a first output increase since 

    - Self-cut, with a ++

  2, join operator

    + May be summed string

  3, the assignment operator

    =  

  4, comparison operators

    == equal, compare values

    === congruent, only compare values ​​further comparison data type

      ! = Not equal

     ! The whole is not equal ==

        > Greater than

       <Less than

     > = Greater than or equal to

     <= Less than or equal to
  5, logical operators

    && is a logical AND flase if the first, the second operation is not skipped, the equivalent of breaking

    || or when the first logic is true, the second operation is not skipped, the equivalent of a short circuit

    ! Logical NOT      

  6, the ternary operator

     if(3>1){

        "aa"

     }else{

        "bb"

     }

              var res = 3> 1 "aa": "bb"; // this is a ternary operator, when 3> 1 is true, take?? Behind the 'aa'; when 3> 1 is false, take? Behind the 'bb'.

  7, comma operator

    A plurality of operation may be performed in a single statement by comma operator

Six other

  <noscript>

    Your browser does not support JavaScript, please see the replacement. // can identify the <script> tag where the browser does not support script

  </noscript>

  

 

      

          

 

 

 

 

 

  

Guess you like

Origin www.cnblogs.com/hebizaiyi/p/11340927.html