坊间传闻,现在的前端面试者的简历都写精通JS,那就拿这些题考考,若不能全答对,就不要说精通了,这只是中高级前端的基础题而已。
1.请问JS中的基本数据类型有几种?( )
2.下面代码的输出是什么?( )
function sayHi() { console.log(name); console.log(age); var name = "TJH"; let age = 24; }
3.下面代码的输出是什么?( )
for (var i = 0; i < 3; i++) { setTimeout(function () { console.log(i); }, 1); } for (let i = 0; i < 3; i++) { setTimeout(function () { console.log(i); }, 1); }
4.下面代码的输出是什么?( )
let a = 666; let b = new Number(666); let c = 666; console.log(a == b); console.log(a === b); console.log(b === c);
5.下面代码的输出是什么?( )
const a = {}; const b = { key: "b" }; const c = { key: "c" }; a[b] = 123; a[c] = 456; console.log(a[b]);
6.下面代码的输出是什么?( )
const numbers = [1, 2, 3]; numbers[10] = 11; console.log(numbers);
7.下面代码的输出是什么?( )
let number = 0; console.log(number++); console.log(++number); console.log(number);
8.下面代码的输出是什么?( )
let obj1 = { name: ‘obj1_name‘, print: function () { return () => console.log(this.name); } } let obj2 = { name: ‘obj2_name‘ }; obj1.print()(); obj1.print().call(obj2); obj1.print.call(obj2)();
9.下面代码的输出是什么?( )
const obj = { 1: "a", 2: "b", 3: "c" }; const set = new Set([1, 2, 3, 4, 5]); obj.hasOwnProperty("1"); obj.hasOwnProperty(1); set.has("1"); set.has(1);
10.下面代码的输出是什么?( )
function Foo() { getName = function () { console.log(1); }; return this; } Foo.getName = function () { console.log(2); } Foo.prototype.getName = function () { console.log(3); }; var getName = function () { console.log(4); }; function getName() { console.log(5); } Foo.getName(); getName(); Foo().getName(); getName(); new Foo.getName(); new Foo().getName(); new new Foo().getName();
11.下面代码的输出是什么?( )
async function async1() { console.log(‘async1 start‘); await async2(); console.log(‘async1 end‘); } async function async2() { console.log(‘async2‘); } console.log(‘script start‘); setTimeout(function () { console.log(‘setTimeout0‘); }, 0); setTimeout(function () { console.log(‘setTimeout3‘); }, 0); setImmediate(() => console.log(‘setImmediate‘)); process.nextTick(() => console.log(‘nextTick‘)); async1(); new Promise(function (resolve) { console.log(‘promise1‘); resolve(); console.log(‘promise2‘); }).then(function () { console.log(‘promise3‘); }); console.log(‘script end‘);
CDCCBCCCCDD
原文:https://www.cnblogs.com/liontone/p/12316504.html