美文网首页JavaScript
《JavaScript高级程序设计》Chapter 3 基本概念

《JavaScript高级程序设计》Chapter 3 基本概念

作者: 云之外 | 来源:发表于2016-09-01 11:38 被阅读68次

    Chapter 3 基本概念

    数据类型

    1. typeof 操作符:
      • undefined 未定义
      • boolean 布尔值
      • string 字符串
      • number 数值
      • object 对象/null
      • function 函数
    2. undefined 是 null 的派生值
      • 声明变量
    3. 浮点数值(IEEE754)
      • 0.1 + 0.2 != 0.3
    4. 数值范围
      • Number.MIN_VALUE ~ Number.MAX_VALUE
      • <: -INFINITY >: INFINITY
      • NaN: Not a Number (NaN != NaN)
    5. 数值转换
      • Number()
      • parseInt()
      • parseFloat()
      • ES5不支持八进制字符串转字符,会忽略前导零,可以使用基数进行进制指定:
        • var number = parseInt("070", 8); //56
    6. Object
      • var o = new Object(); // Create an Object
      • constructor: Object()
      • hasOwnProperty("propertyName")
      • isPrototypeOf(object)
      • propertyIsEnumerable("propertyName")
      • toLocaleString()
      • toString()
      • valueOf()

    操作符

    1. 增减操作符

      • var s1 = "2"; s1++; // 变成数值 3
      • var s2 = "z"; s2++; // 变成NaN
      • var b = false; b++; // 变成数值1
      • var f = 1.1; f--; // 变成数值0.10000000000000009
      • 运算符重载
        var o = {
        valueOf: function() {
                          return -1;
                       }
        };
      
    2. 位运算

      • & | ~
      • << >>
      • ^ 异或 (只有一个1才返回1)
    3. 相等

      • == != 相等和不相等
      • === !== 全等和不全等
      • "55" == 55
      • "55" !== 55 (全等会比较类型和数据)

    语句

    1. for-in 语句

      • for (property in expression) statement;
      • 通过for-in输出对象的属性的顺序是不可预测的。
    2. label break continue 组合语句

    3. with 语句 (Not Recommanded)

      • 作用:将代码的作用域设置到一个特定的对象中。
      • with (expression) statement;
      • example:
      // without with:
      var qs = location.search.substring(1);
      var hostName = location.hostname;
      var url = location.href;
      
      // use with:
      with (location) {
          var qs = search.substring(1);
          var hostName = hostname;
          var url = href;
      }
      

    函数

    1. 语法

      function functionName(arg1, arg2, ...) {
          statements
      }
      
    2. 严格模式中...

      • 函数名不能为eval或arguments
      • 参数名不能为eval或arguments
      • 不能出现两个命名参数同名的情况
    3. 在函数体内可以通过arguments对象访问参数数组,从而获取传递给函数的每一个参数。

      function sayHi() {
          alert("Hello" + arguments[0] + "," + arguments[1]);
      }
      

      可以利用这一特点让函数接收任意个参数

    相关文章

      网友评论

        本文标题:《JavaScript高级程序设计》Chapter 3 基本概念

        本文链接:https://www.haomeiwen.com/subject/dbbcettx.html