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();
  • 相关阅读:
    Django如何把数据库里的html格式输出到前端
    如何修改Django中的日期和时间格式 DateTimeField
    python2.7无法安装python-ldap、django-auth-ldap
    windows10下Python如何设置环境变量
    微信小程序在开发者工具页面显示空白且控制台看不到报错信息
    CentOS7 升级 openssh 到 openssh-8.0p1版本
    CentOS系统升级OpenSSH版本
    SSL相关漏洞解决方法
    CentOS 7.4安装 MySQL数据库
    Python3 基础知识
  • 原文地址:https://www.cnblogs.com/qhhw/p/6511160.html
Copyright © 2011-2022 走看看