• 【前端笔试】关于一些输入输出


          let str = '000500';
            let res = +str.substr(2, 2);
            console.log(res);
            getRes(res);
            str = '0';
            getRes(res);
            console.log(res);
    
            function getRes(res) {
                res = str && (str = +str) || 'ok';
                console.log(res);
            }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    结果:
    在这里插入图片描述

     let a = typeof(function f() {
                return "1";
            }, function g() {
                return 2;
            })()
            console.log(a);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    在这里插入图片描述

      function foo(a) {
                console.log(a + b);
            }
            var a = 3;
            var b = 4;
            foo(2);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    在这里插入图片描述
    以下6个代码片段,会打印两次 ‘got it’ 的是哪些?

    //片段1
    var p = new Promise((resolve, reject) => {
                    reject(Error('got it'))
                })
                .catch(error => console.log(error))
                .then(error => console.log(error))
    
    //片段2
            new Promise((resolve, reject) => {
                    resolve('got it')
                }).then(() => {
                    throw Error('got it')
                })
                .catch(error => "got it")
                .catch(error => console.log(error.message))
    
    //片段3
    
            var p = new Promise((resolve, reject) => Promise.reject(Error('got it')))
            p.catch(error => console.log(error.message))
            p.catch(error => console.log(error.message))
    
    //片段4
            var p = new Promise((resolve, reject) => {
                    reject(Error('got it'))
                })
                .catch(error => console.log(error.message))
                .catch(error => console.log(error.message))
    
    //片段5
            Promise.resolve('got it').then(data => data).then(data => {
                console.log(data)
                return data
            }).then(console.log)
    
    //片段6
            var p = new Promise((resolve, reject) => {
                reject(Error('got it'))
            })
            p.catch(error => console.log(error.message))
            p.catch(error => console.log(error.message))
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41

    第一个片段打印出来的结果:
    在这里插入图片描述
    第2个片段打印出来的结果:
    无输出
    第3个片段打印出来的结果:
    在这里插入图片描述
    第4个片段打印出来的结果:
    在这里插入图片描述
    第5个片段打印出来的结果:
    在这里插入图片描述
    第6个片段打印出来的结果:
    在这里插入图片描述
    在JavaScript中, 有
    A typeof function() {} === typeof {}
    B typeof Date === typeof RegExp
    C typeof {} === typeof []
    D object.prototype.tostring.call([]) === typeof []

     console.log(typeof
              function() {} === typeof {});
            console.log(typeof Date === typeof RegExp);
            console.log(typeof {} === typeof []);
            console.log(object.prototype.tostring.call([]) === typeof []);
    
    • 1
    • 2
    • 3
    • 4
    • 5

    在这里插入图片描述

     for (let i = 0; i < 5; ++i) {
                setTimeout(function() {
                    console.log(i);
                }, 1000);
            }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    在这里插入图片描述

  • 相关阅读:
    Vue中如何实现动态改变字体大小
    归纳总结笔记
    基于MAX-10 FPGA 超声波测距模块HC_SR04
    [附源码]计算机毕业设计JAVA同城搬家平台
    JavaScript 中的灵活编程模式-行为委托
    Linux高负载排查最佳实践
    ajax请求
    Linux | 从虚拟地址到物理地址
    数字安全实操AG网址漏洞扫描原理与技术手段分析
    即用型UI组件Kendo UI,助力惠普缩短40%的应用开发时长
  • 原文地址:https://blog.csdn.net/qq_40992225/article/details/126729419