• JavaScript入门(2)


    encodeURI()和 decodeURI()作用  编码与解码

    encodeURIComponent()和 decodeURIComponent()作用区别是  后者可以处理一些特殊字符进行转义

    var s1='美眉.jpg=?8888';
    var s2=encodeURI(s1);
    console.log('s2='+s2);
    var s3=decodeURI(s2);
    console.log('s3='+s3);

    var s4=encodeURIComponent(s1);

    var s5=encodeURIComponent(s4);

    console.log('s4='+s4);
    console.log('s5='+s5);

    输出结果:

    test.html:19 s2=%E7%BE%8E%E7%9C%89.jpg=?8888
    test.html:21 s3=美眉.jpg=?8888
    test.html:27 s4=%E7%BE%8E%E7%9C%89.jpg%3D%3F8888
    test.html:28 s5=%25E7%25BE%258E%25E7%259C%2589.jpg%253D%253F8888

    对象 

    对象的三种赋值:

    1、字面量赋值: var emp={

        empno:7788,

        ename: 'scott',

        sal:8888

    };

    console.log(emp+' typeof(emp)'+typeof(emp));
    console.log(emp.empno);
    console.log(emp['empno']);

    输出结果:

    访问对象中的属性值得两种方法:

      1、  对象加点访问

      2、对象加中括号接字符串访问,字符串是名值对中的名字 

    2、new 构造函数

    3、表达式 :  eavl(字符串);

    几种变量的类型:

    typeof(null);
    "object"


    typeof(object);
    "undefined"


    typeof(undefined);
    "undefined"


    undefined==null;
    true

    if的用法

    if()的判断 条件 :  括号中为广义上的0 ,   非0即真,  广义上的0 有很多的情况。

    要区分下面情况:

    //var x=new Boolean();    假
    //var x=new Boolean(false);  真    对象不是广义上的0
    var x=new Boolean('false');     真
    if(x){
    console.log('if (true) {}'+x);

    } else{
    console.log('else'+x);
    }

     广义上的0 有:undefined , null,NaN,空串,数值0,false,其他不是。

    in 的用法

    1、判断元素是否在对象中 返回boolean类型

    2、  遍历对象:  for...in 

    <script>
    var emp={
    empno :7788,
    ename: 'abc',
    sal: 9999
    };

    for(var attr in emp){
    console.log(attr+' : '+emp[attr]);
    }

    </script>

    输出结果:

    test.html:23   empno : 7788
    test.html:23   ename : abc
    test.html:23   sal : 9999

    异常处理:


    try{
    console.log(x);
    }catch(e){
    console.info('-----'+e);
    }finally{
    console.log('......');
    }

    输出结果:

    test.html:33 -----ReferenceError: x is not defined
    test.html:35 ......

  • 相关阅读:
    吴恩达 机器学习笔记
    三个水杯
    架构之美读书笔记05
    架构之美读书笔记04
    架构之美读书笔记03
    架构之美读书笔记02
    架构之美读书笔记01
    《需求工程——软件建模与分析》阅读笔记03
    《需求工程——软件建模与分析》阅读笔记02
    16下学期进度条2
  • 原文地址:https://www.cnblogs.com/jiangyi666/p/5780188.html
Copyright © 2020-2023  润新知