数字和字符串比较

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
    </head>
    <body>
    </body>
    <script>
      /**字符串之间的对比***/
      function test(){
        alert(1<3);//true;
        /**字符串数字之间的对比,会先转化成数字**/
        alert("1"<"3");//true
        /**纯字符串比较 会先转成ascii码**/
        alert("a"<"b");//true
        /***汉字对比 转码**/
        alert("我".charCodeAt());//25105;
        alert("的".charCodeAt());//30340
        alert("我"<"的");//true
        /**数字和字符串数字比较***/
        alert(123<"124");//true 数字和字符串数字比较 会首先将字符串数字做比较。
        /**数字和字符串非数字比较***/
        alert(123<"sss");//sss返回NaN 不管如何都返回为假
      }
      test();
    </script>
</html>

posted @ 2015-05-06 15:12  独孤残情  阅读(252)  评论(0编辑  收藏  举报