日期:2014-05-16  浏览次数:20288 次

JavaScript----数字, 字符串, 布尔类型
1. 数字类型(numbers)
   1.1 javascript不区分整型和浮点型,所有呈现的都是浮点型,并且是64位的浮点型。
   1.2 数字类型支持正常的+, -, *, /, %操作,并且可以通过Math对象实现复杂点的数学运算。
   1.3 javascript不会抛出错误,当出现溢出和下溢和被0整除的情况。
   1.4 示例:
        var n = 123456.789;
        n.toFixed(0);         // "123457"
        n.toFixed(2);         // "123456.79"
        n.toFixed(5);         // "123456.78900"
        n.toExponential(1);   // "1.2e+5"
        n.toExponential(3);   // "1.235e+5"

        n.toPrecision(4);     // "1.235e+5"
        n.toPrecision(7);     // "123456.8"
        n.toPrecision(10);    // "123456.7890"

2. strings
   2.1 var s = "hello, wolrd"
       s.length
       s.charAt(0)
       s.substring(1,4)
       s.slice(1,4)
       s.slice(-3)
       s.indexOf("1")
       s.lastIndexOf("1")
       s.indexOf("1",3)
       s.split(",")
       s.replace("h", "H")
       s.toUpperCase()
   2.2 In ECMAScript 5, 字符串可以当作只读的数组,可以访问单个的字符,通过使用方括号代替charAt()方法:
       s = "hello, world";
       s[0]
       s[s.length-1]

3. Boolean Values
   3.1 布尔类型只可能有两种值: true, false
   3.2 JavaScript中任意值都可以转换为布尔值,下面的值的作用就好比false:
        undefined
        null
        0
        -0
        NaN
        ""         // the empty string
       All other values, including all objects (and arrays) convert to, and work like, true.
   3.3 布尔值有一个toString()方法,可以将他们从字符串转换为"true" or "false", 但是他们没有任何其他的有用的方法。