• js3:数据类型,数组,String各个属性,以及字符串表达式用eval计算


    原文发布时间为:2008-11-08 —— 来源于本人的百度文章 [由搬家工具导入]

    <html>
    <head>
    <title>js</title>

    <script type="text/JavaScript">
    <!--
    var v;
    document.write(typeof(v)+"<br>");
    v="hello";
    document.write("<h1>"+typeof(v)+"</h1>");
    v=1;
    document.write(typeof(v)+"<br>");
    v=1.5;
    document.write(typeof(v)+"<br>");
    v=2.0e3;
    document.write(v+"<br>");
    v=true;
    document.write(typeof(v)+"<br>");
    v=null;
    document.write(typeof(v)+"<br>");
    var arr=new Array(2);
    arr[0]="hi";
    arr[1]="2hi";
    var arr2=new Array();
    arr2[3]="3hi";
    for(var i=0;i<arr.length;i++)
    document.write(arr[i]+"<br>");
    for(var i=0;i<arr2.length;i++)
    document.write(arr2[i]+"<br>");
    document.write(arr2.length+"<br>");
    document.write(arr[0]*5+"<br>");
    var num=5;
    var str="5";
    document.write((num==str)+"<br>");
    document.write((num===str)+"<br>");
    document.write((num!=str)+"<br>");
    document.write((num!==str)+"<br>");
    var newstr="JavaScript";
    document.write(newstr.fontcolor('red')+"<br>");
    document.write(newstr.bold()+"<br>");
    document.write(newstr.indexOf("aS",2)+"<br>");
    document.write(newstr.indexOf("aS",4)+"<br>");
    document.write(newstr.lastIndexOf("aS",3)+"<br>");
    document.write(newstr.lastIndexOf("aS",2)+"<br>");
    var arrstr=newstr.split('a');
    for(var i=0;i<arrstr.length;i++)
    document.write(arrstr[i]+" ");

    document.write("<br>"+newstr.substring(1,5)+"<br>");
    document.write(newstr.toLowerCase()+"<br>");
    document.write(newstr.toUpperCase()+"<br>");
    var cacu="23"+"*"+"5";
    document.write(cacu+"<br>");
    document.write(eval(cacu)+"<br>");
    //-->
    </script>
    </head>
    <body>
    </body>
    </html>

    运行结果:

    undefined

    string

    number
    number
    2000
    boolean
    object
    hi
    2hi
    undefined
    undefined
    undefined
    3hi
    4
    NaN
    true
    false
    false
    true
    JavaScript
    JavaScript
    3
    -1
    3
    -1
    J v Script
    avaS
    javascript
    JAVASCRIPT
    23*5
    115

  • 相关阅读:
    CodeForces
    CodeForces
    AtCoder
    AtCoder
    CodeForces
    CodeForces
    CodeForces
    CodeForces
    Centos7配置yum国内镜像及仓库升级
    环境变量
  • 原文地址:https://www.cnblogs.com/handboy/p/7148412.html
Copyright © 2020-2023  润新知