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


          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

    在这里插入图片描述

  • 相关阅读:
    【重识云原生】第四章云网络4.7.2节——virtio网络半虚拟化简介
    考察软件开发公司的能力
    Apollo预测模块启动及调试
    在MDK-Keil中开发S32K144
    vue首页多模块布局(标题布局)
    简易备忘录
    【openGauss】在windows中使用容器化的mogeaver
    Azure - 机器学习企业级服务概述与介绍
    阿里云视频点播+项目实战
    Linux 安装Mysql 详细教程
  • 原文地址:https://blog.csdn.net/qq_40992225/article/details/126729419