前端笔试题总结(一) - JS篇
发布日期:2021-05-10 03:19:20 浏览次数:18 分类:精选文章

本文共 3886 字,大约阅读时间需要 12 分钟。

  • ���������������������

    var x = 0;
    x = x++;
    console.log("x: " + x); // 0
  • ���������������������������������

    var c = "10", d = 10, f = false;
    var y;
    console.log("c + d: " + (c + d), ", c + f: " + (c + f), ", d + f: " + (d + f));
    // c+d: 1010, c+f: 10false, d+f: 10
    console.log("d + y"); // NaN
  • ���������������������������

    var r1 = ["arr1", "arr2", "arr3"];
    var r2 = new Array("arr1", "arr2", "arr3");
    var r3 = Array("arr1", "arr2", "arr3");
  • ������������������������������������������

    // ������������JS������������������������������
  • ������������������������������

    var a = 3.1515;
    var b = 3.1525;
    var c = 3.1535;
    var d = 3.1545;
    var e = 3.1555;
    var f = 3.1565;
    var g = 3.1575;
    var h = 3.1585;
    var i = 3.1595;
    var j = 3.1505;
    console.log(a.toPrecision(4)); // 3.151
    console.log(b.toPrecision(4)); // 3.152
    console.log(c.toPrecision(4)); // 3.154
    console.log(d.toPrecision(4)); // 3.155
    console.log(e.toPrecision(4)); // 3.155
    console.log(f.toPrecision(4)); // 3.156
    console.log(g.toPrecision(4)); // 3.158
    console.log(h.toPrecision(4)); // 3.159
    console.log(i.toPrecision(4)); // 3.159
    console.log(j.toPrecision(4)); // 3.151
  • typeof������������������

    var x = typeof 123;
    var x = typeof(123);
    console.log(x); // 'number'
  • null���undefined���������

    var one;
    var two = null;
    console.log(one == two, one === two); // true, false
  • ���������������������������

    console.log(+new Date()); // 1619089280052
  • IIFE���������������������

    for(var i = 0; i < 5; i++){
    (function(i){
    setTimeout(function(){
    console.log(i);
    }, 5000);
    })(i);
    }
  • eval()���������������

    eval("console.log('eval test');"); // eval test
  • JSON���������������������

    var info = '{"name":"guangtailang","age":22}';
    var heroGuang = JSON.parse(info);
    console.log(heroGuang.name); // guangtailang
    var heroGuang = {name: "guangtailang", age: 22};
    var info = JSON.stringify(heroGuang);
    console.log(info); // {name: "guangtailang", age: 22}
    console.log(typeof info); // string
  • ������DOM���������������

    document.getElementById("no1");
    document.getElementsByClassName("box");
    document.getElementsByTagName("p");
    document.getElementsByName("user");
    document.querySelector("#div1");
    document.querySelectorAll(".div1");
  • ���������������������������������

    var heroGuang = {name: "guangtailang", age: 22};
    console.log(heroGuang['name']); // [ ]������������������������
    console.log(heroGuang.name); // . (���������) ���������
    heroGuang['111'] = 222;
    console.log(heroGuang['111']); // 222
  • ������������������������

    function.invoke(...)    // ������
    function.Execute(...) // ������
    function.Apply(...) // ������
    function.exec(...) // ������������������
    console.log(str.match(re));
  • JSON���������������������

    var str = 'The Quick Brown Fox Jumps Over The Lazy Dog';
    var re = /quick\s(brown).+?(jumps)/ig;
    var result1 = re.exec(str);
    var result2 = str.match(re);
    console.log(result1);
    console.log(result2);
  • ���������������������

    fun.call(thisObj, arg1, arg2); // ������������������������������
    args = [arg1, arg2, arg3...];
    fun.apply(thisObj, args); // ������������������������������
    var newFun = fun.bind(thisObj); // ������������������������������������
    newFun(arg1, arg2, ...);
  • Object.keys()���������

    var a = {1: "one", 2: "two", 3: "three"};
    var b = Object.keys(a);
    console.log(b); // ["1", "2", "3"]
  • typeof������������������

    console.log(typeof a); // undefined
    var a = [typeof a, typeof y][0];
    console.log(typeof a); // string
    var b = typeof typeof a;
    console.log("a: " + a); // undefined
    console.log("b: " + b); // b: string
    console.log(typeof undefined); // undefined
    console.log(typeof typeof undefined); // string
    console.log(typeof undefined === undefined); // false
    console.log(typeof undefined === "undefined"); // true
    console.log(typeof typeof undefined === "string"); // true
  • ������������������������������������������������������������������JavaScript���������������������������������������������������

    上一篇:前端笔试题总结(二) - HTML篇
    下一篇:原型与原型链详解

    发表评论

    最新留言

    关注你微信了!
    [***.104.42.241]2025年04月18日 10时43分21秒