zoukankan      html  css  js  c++  java
  • js常见易错笔试题

    var test='hello world';
    console.log(this.test);//this指全局window
    var test1 = {
    test:'hello zhongguo',
    func:function(){
    return this.test;
    }
    }
    var func = test1.func;
    console.log(func()); //如果func=test1.func();则console.log(func);输出为hello zhongguo
    //结果:hello world
    // hello world

    /*var data = ['北京','上海','广州','深圳'];
    Array.prototype.getLength = function(){
    var length = data.length;
    return length;
    };
    for(var i=0;i<data.length;i++){
    console.log(typeof i);//number 0,1,2,3
    console.log(data[i]); //打印:北京 上海 广州 深圳
    }
    for(var i in data){
    console.log(i);
    console.log(typeof i);//string '1','2','2','3'
    console.log(data[i]);//打印:北京 上海 广州 深圳 function(){var length = data.length;return length; }
    }
    */
    var test = 'shanghai';
    function New(){};
    console.log(typeof test);// string
    console.log(New instanceof Object);// true

    var txt='xixi';
    function hello(){
    var txt;
    fn(); //world
    var fn=function(){ //这是函数表达式
    console.log('hello');
    };
    function fn(){console.log('world');};
    console.log(txt);//undefined 自己作用域内有txt变量则不会去父层找,如果没有则找外层的
    fn();// hello
    }
    hello();
    /*其中:var fn=function(){console.log('hello'); };是函数表达式;整个执行过程相当于:
    var txt='hx';
    function hello(){
    var txt;
    var fn;
    function fn(){console.log('world');};函数声明提前
    fn();
    fn=function(){console.log('hello');
    console.log(txt); 自己作用域内有txt变量则不会去父层找,如果没有则找外层的
    fn();
    }

    打印结果:
    world
    undefined
    hello
    */
    /*(function(){
    var a=b=5; //a是局部变量 b是在全局作用域下
    })();
    console.log(a);//报错 :访问不到上面函数内部的局部变量
    console.log(b);//结果:5
    */


    function test0(){
    console.log(a);//undefined
    console.log(foo());//2 函数声明提前并执行
    var a=1;
    function foo(){
    return 2;
    }
    };
    test0();
  • 相关阅读:
    使用PHP模拟post提交数据
    window.event.keycode值大全
    php采集
    自己写的一个简单PHP采集器
    php如何实现定时任务,php定时任务方法,最佳解决方案,php自动任务处理
    关于delphi软件运行出现Invalid floating point operation的错误的解决办法
    delphi编程创建桌面快捷方式
    BCB直接访问硬件端口和物理内存
    delphi winio 输入
    总是说spring难学?来看完这些spring的注解及其解释,真香!
  • 原文地址:https://www.cnblogs.com/qhhw/p/6511160.html
Copyright © 2011-2022 走看看