zoukankan      html  css  js  c++  java
  • Javascript Basic Operation Extraction

    1.  logic operation : '&&' and '||'  .For this two logic operations,its' results are inconclusive.the difference between this two logic operations  and others is that they don't change the data type of the operands and also don't change the data type of the operation result. In the expression , this operator(&& and ||) will understand the type of the operands as the bool type ,so they can  execute bool operation.you can have a look below.

              

     1 <html>
     2         <head>
     3         <meta  http-equiv="content-type" charset="utf-8"/>
     4         <script type="text/javascript">
     5         var str = "hello";
     6         var obj = {};
     7         alert(str || obj);//str as string type ,obj as an object,return str("hello")
     8         alert(str && obj);//return obj
     9         alert(undefined || 123);//undefined as false,and return 123
    10         </script>
    11         </head>
    12         <body> 
    13         </body>
    14 </html>

    2.  comparison operation. For comparing two value type data,generally just compare their values.For comparing a value type data and a reference type data,first switch the reference type data to the same type as the value type data,then compare them.For comparing two reference type data,it's unmeaning and always return false.like below:

          

     1 <html>
     2         <head>
     3         <meta  http-equiv="content-type" charset="utf-8"/>
     4         <script type="text/javascript">
     5         var o1 = {};
     6         var o2 = {};
     7         var str = "123";
     8         var num = 1;
     9         var b0 = false;
    10         var b1 = true;
    11         var ref = new String();
    12         
    13         alert(b1 < num);//return false;
    14         alert(b1 <= num);//return true;
    15         alert(b1 > b0);//return true;
    16         
    17         alert(num > ref);//return true;
    18         
    19         alert(o1 > o1 || o1 < o2 || o1 == o2);//always return false;
    20         </script>
    21         </head>
    22         <body> 
    23         </body>
    24 </html>

              

  • 相关阅读:
    一段笑话
    遇到了DIV被下拉框挡住的问题,2天没有解决了~晕死我了#)
    盘点JavaScript中5个常用的对象
    C# ARGB转RGB之Alpha通道混合与亮度
    工作进度进度条js
    一个很漂亮的图片浏览效果js
    很好的几个js滑动条效果
    实现textarea限制输入字数
    Asp 出现Microsoft JScript 编译错误 (0x800A03EC) 缺少 ';'解决办法
    Request.UrlReferrer详解
  • 原文地址:https://www.cnblogs.com/oxf5deb3/p/3704067.html
Copyright © 2011-2022 走看看