for (var i = 0; i < 3; i++) {setTimeout(_ => {console.log(i)})}for (let i = 0; i < 3; i++) {setTimeout(_ => {console.log(i)})}
- 下面程序的输出结果是:
console.log(a);var a = 'a';console.log(b);let b = 'b';
- 下面程序的输出结果是:
var foo = "Hello";(function(){var bar = " World";alert(foo + bar);})();alert(foo + bar);
- 下面程序的输出结果是:
var a = 10;(function () {console.log(a)a = 5console.log(window.a)var a = 20;console.log(a)})()
- 下面代码的输出结果是:
const a = 10function runFunction() {const a = 20console.log('inside', a)}runFunction()console.log('outside', a)
- 请描述打印结果并说明原因
"use strict"var name = 'Jay'var person = {name: 'Wang',pro: {name: 'Michael',getName: function () {return this.name}}}console.log(person.pro.getName)var people = person.pro.getNameconsole.log(people())
- 下面程序的结果是:
<ul><li>1</li><li>2</li><li>3</li><li>4</li></ul><script>var elements = document.getElementsByTagName("li");for (var i=0;i<elements.length;i++){elements[i].onclick =function( ){alert(i);};}
- 下面程序的输出结果是
compute(10,100);var compute = function(A,B) {console.info(A * B) ;};function compute(A,B){console.info(A + B);}function compute(A,B){console.info((A + B)*2);}compute(2,10);
- 下面程序的执行结果是:
meili()function meili() {console.log("meili")}mogu()var mogu = function() {console.log("mogu")}
- 下面两个代码片段输出结果有什么区别?为什么?
// 片段1check('first');function check(ars){console.log(ars);}// 片段2check('second');var check= function(ars){console.log(ars);}
ES6对象- 下面代码的输出结果是?
const student = {name: 'ZhangSan'}Object.defineProperty(student, 'age', {value: 22})console.log(student)console.log(Object.keys(student))
generator- 下列程序的输出结果是多少?为什么?
function * cb(x, y) {for(let i = Math.ceil(x); i <= y; i++) {yield i;}}var a = cb(6, 9);console.log(a.next());console.log(a.next());
扩展运算符- 下面程序的输出结果是:
function fn(...args) {console.log(typeof args);}fn(21);
promisePromise.reject(0).catch(e => e).catch(e => console.log(e))
class- 请写出下面ES6代码编译后所生成的ES5代码
class Person {constructor (name) {this.name = name;}greet () {console.log(`Hi, my name is ${this.name}`);}greetDelay (time) {setTimeout(() => {console.log(`Hi, my name is ${this.name}`);}, time);}}
标签模板- 下面程序的输出结果是多少?
function getPersonInfo (one, two, three) {console.log(one)console.log(two)console.log(three)}const person = 'Lydia'const age = 21getPersonInfo `${person} is ${age} years old`
module- 请写出index里面的输出结果
// module.jsexport default () => "Hello world"export const name = "nowcoder"// index.jsimport * as data from "./module"console.log(data)
- 有a.js和b.js两个文件,请写出b文件中代码的输出
// a.jslet a = 1let b = {}setTimeout(() => {a = 2b.b = 2}, 100)module.exports = { a, b }// b.jsconst a = require('./a')console.log(a.a)console.log(a.b)setTimeout(() => {console.log(a.a)console.log(a.b)}, 500)
其他- 输出结果是:
<div id="box1"><div id="box2">content</div></div><script>const $ = document.querySelector.bind(document);const box1 = $('#box1');const box2 = $('#box2');box1.addEventListener('click', () =>{console.log('box1 true');}, true);box1.addEventListener('click', () =>{console.log('box1 false');}, false);box2.addEventListener('click', () =>{console.log('box2 true');}, true);box2.addEventListener('click', () =>{console.log('box2 false');}, false);</script>
推荐阅读
- 移动前端开发和 Web 前端开发的区别是什么?
- 当下最火的前端面试题,回溯算法来了
- php大文件切片上传
- 轻量、高效、功能强大的微前端框架-MicroApp
- 前端领域如何实现请求中断
- 前端开发之动态管理Nginx集群的方法
- 5 个网站将您的前端技能提升 100 倍
- 文档如何自动化部署到线上环境「每个前端都可以拥有自己的博客」
- 前端开发干货:让 iframe 焕发新生开发
- 前端新手必备常用JavaScript方法函数大全