标签:不包含 ase back 表示 syn lang foo 指定 erro
以下题目来自Duing公众号,本文所有题目已获得原作者授权
var foo=function bar(){}
console.log(typeof bar);
var a=1;
if(true){
console.log(a);
let a=2;
}
var a=[1,2,3,3,5,6,6,6,‘A‘,undefined,true,null]
var s=new Set(a);
console.log(s.size);
let arr1=[1,2,3,4,5];
let arr2=[4,5,6,7,8];
let x=1;
function f1(x,y=x){
console.log(y);
}
function f2(y=x){
let x=0;
console.log(y);
}
f2(2);
f1();
fn(123)
var a=456;
function fn(a){
console.log(a);
}
function F(){
this.a=1;
}
var obj=new F();
console.log(obj.prototype);
if(false){
var a=1;
let b=2;
}
console.log(a);
console.log(b);
let arr1=[1,2,3,4,5];
let arr2=[4,5,6,7,8]
var [a=3,b=a,c=3]=[1,2,undefined];
<ul id="list">
<li>百度</li>
<li>阿里</li>
<li>腾讯</li>
</ul>
<script>
var list=document.getElementById(‘list‘);
var lis=list.querySelectorAll(‘li‘);
list.replaceChild(lis[2],lis[1]);
list.insertBefore(lis[1],list.children[2]);
</script>
var c=1;
function c(){
console.log(c);
var c=3;
}
console.log(c);
c(2);
var name=‘kaivan‘;
(function () {
if(typeof name===‘undefined‘){
var name=‘chen‘;
console.log(name);
}else {
console.log(name);
}
})();
var a=10;
function test() {
a=100;
console.log(a);
console.log(this.a);
var a;
console.log(a);
}
test();
if(!(‘a‘ in window)){
var a=1;
}
console.log(a);
var val=1;
var obj={
val:2,
del:function () {
console.log(this);
this.val*=2;
console.log(val);
}
}
obj.del();
var name=‘kaivon‘;
var object={
name:‘chen‘,
getNameFunc:function () {
return function () {
return this.name;
}
}
}
console.log(object.getNameFunc()())
var name=‘kaivon‘;
var object={
name:‘chen‘,
getNameFunc:function () {
var that=this;
return function () {
return that.name;
}
}
}
console.log(object.getNameFunc()())
var a=6;
setTimeout(function () {
a=666;
},0)
console.log(a);
(function () {
var a=b=3;
})();
console.log(typeof a===‘undefined‘);
console.log(typeof b===‘undefined‘)
var a=(function (foo) {
return typeof foo.bar;
})({foo:{bar:1}});
console.log(a);
function f() {
return f;
}
console.log(new f() instanceof f);
function A() {}
A.prototype.n=1;
var b=new A();
A.prototype={
n:2,
m:3,
}
var c=new A();
console.log(b.n,b.m);
console.log(c.n,c.m)
console.log(false.toString());
console.log([1,2,3].toString());
console.log(1.toString());
console.log(5..toString());
console.log(1 + ‘2‘ + ‘2‘);
console.log(1 + +‘2‘+ ‘2‘);
console.log(+ ‘1‘ - +‘1‘+‘2‘);
console.log(‘A‘ - ‘B‘ + ‘2‘);
console.log(‘A‘ - ‘B‘ + 2)
var a=666;
console.log(++a);
console.log(a++);
console.log(a);
var a={n:1};
var b=a;
a.x=a={n:2};
console.log(a.n,b.n);
console.log(a.x,b.x);
console.log(c);
function c(a) {
console.log(a);
var a=3;
function a() {
}
}
c(2);
console.log(typeof a);
function a() {};
var a;
console.log(typeof a);
var a;
var b=‘undefined‘;
console.log(typeof a);
console.log(typeof b);
console.log(typeof c);
var obj={n:1};
function fn2(a) {
a.n=2;
}
fn2(obj);
console.log(obj.n);
var x=10;
function fn() {
console.log(x);
}
function show(f) {
var x=20;
fn();
}
show(fn);
Object.prototype.bar=1;
var foo={
goo:undefined
};
console.log(foo.bar);
console.log(‘bar‘ in foo);
console.log(foo.hasOwnProperty(‘bar‘));
console.log(foo.hasOwnProperty(‘goo‘));
Object.prototype.bar=1;
var foo={
moo:2,
}
for(var i in foo){
console.log(i);
}
function foo1() {
return{
bar:‘hello‘
};
}
function foo2() {
return{
bar:‘hello‘
};
}
console.log(foo1());
console.log(foo2());
console.log(function () {
return typeof arguments;
}())
console.log(Boolean(false));
console.log(Boolean(‘0‘));
console.log(Boolean(‘‘));
console.log(Boolean(NaN));
var x=1;
if(function f (){}){
x+typeof f;
}
console.log(x);
console.log(‘b‘+‘a‘+ + +‘a‘+‘a‘)
var obj={
a:1,
b:2
}
Object.setPrototypeOf(obj,{c:3});
Object.defineProperty(obj,‘d‘,{value:4,enumerable:false});
for(let prop in obj){
console.log(prop);
}
var x=10;
var foo={
x:90,
getX:function () {
return this.x;
}
};
console.log(foo.getX());
var xGetter=foo.getX;
console.log(xGetter());
console.log(sum(2,3));
console.log(sum(2)(3))
for(var i=0;i<5;i++){
var btn=document.createElement(‘button‘);
btn.appendChild(document.createTextNode(‘按钮‘+i));
btn.addEventListener(‘click‘,function () {
console.log(i);
})
document.body.appendChild(btn);
}
var d={};
var b=[‘car‘,‘house‘];
b.forEach(function (k) {
d[k]=undefined;
})
console.log(d);
var arr1=‘john‘.split(‘‘);
var arr2=arr1.reverse();
var arr3=‘jones‘.split(‘‘);
arr2.push(arr3);
console.log(‘arr1:length=‘+arr1.length+‘last=‘+arr1.splice(-1));
console.log(‘arr2:length=‘+arr2.length+‘last=‘+arr2.splice(-1));
console.log("0 || 1="+(0||1));
console.log(‘1 || 2=‘+(1||2));
console.log(‘0&&1=‘+(0&&1));
console.log(‘1&&2‘+(1&&2));
var a={}
b={key:‘b‘};
c={key: ‘c‘};
a[b]=123;
a[c]=456;
console.log(a[b]);
console.log(a[c]);
(function (x) {
return (function (y) {
console.log(x);
})(2)
})(1);
var length=10;
function fn() {
console.log(this.length);
}
var obj={
length:5,
method:function (fn) {
fn();
arguments[0]();
}
};
obj.method(fn,1);
var myObject={
foo:‘bar‘,
func:function () {
var self=this;
console.log(‘outer func: this.foo=‘+this.foo);
console.log(‘outer func: self.foo=‘+self.foo);
(function () {
console.log(‘inner func :this.foo=‘+this.foo);
console.log(‘inner func :self.foo=‘+self.foo)
})()
}
}
myObject.func();
- A、for...in循环遍历不到继承的属性
- B、do...while在判断条件前会执行一次代码块
- C、for循环中三个表达可以省略,分号也可以省略
- D、while循环语句至少会执行循环体一次
function output(a) {
console.log(a);
}
output(typeof function () {
output(‘Hello World!‘)
}())
function test() {
var n=1573;
function add() {
n++;
console.log(n);
}
return {n:n,add:add}
}
var result=test();
var result2=test();
result.add();
result.add();
console.log(result.n);
result2.add();
var b=1;
function outer() {
var b=2;
function inner() {
b++;
var b=3;
console.log(b);
}
inner();
}
outer();
var settings={
username:‘alan‘,
level:19,
health:90
}
var data=JSON.stringify(settings,[‘level‘,‘health‘]);
console.log(data);
function Dog(name) {
this.name=name
}
Dog.prototype.bark=function () {
console.log(`Woof I am ${this.name}`)
}
const pet=new Dog(‘Mara‘);
pet.bark();
delete Dog.prototype.bark;
pet.bark();
function greeting() {
throw "Hello world!";
}
function sayHi() {
try {
const data=greeting();
console.log(‘It worked!‘,data)
}catch (e) {
console.log("Oh no error:",e);
}
}
sayHi();
function getInfo(member,year) {
member.name=‘Lydia‘;
year=‘1998‘
}
const person={
name:‘Alan‘
}
const birthYear=‘1997‘;
getInfo(person,birthYear);
console.log(person,birthYear)
const newArr=[1,2,3].map(n=>{
if(typeof n===‘number‘) return;
return n*2;
})
const firstPromise=new Promise((res,rej)=>{
setTimeout(res,500,‘one‘)
});
const secondPromise=new Promise((res,rej)=>{
setTimeout(res,100,‘two‘)
});
Promise.race([firstPromise,secondPromise]).then(res=>{
console.log(res)
})
function sayHi(){
console.log(name);
console.log(age);
var name=‘Lydia‘;
let age=21;
}
for(var i=0;i<3;i++){
setTimeout(()=>{
console.log(i);
},1)
}
for(let i=0;i<3;i++){
setTimeout(()=>{
console.log(i);
},1)
}
const shape={
radius:10,
diameter(){
return this.radius*2
},
perimeter:()=>2*Math.PI*this.radius
}
console.log(shape.diameter());
console.log(shape.perimeter());
- A、20and 62.83185307179586
- B、20和NaN
- C、20和63
- D、NaN和63
const bird={
size:‘small‘
}
const mouse={
name:‘Micky‘,
small:true
}
async function getData(){
return await Promise.resolve("I made it!");
}
const data=getData();
console.log(data);
class Chameleon{
static colorChange(newColor){
this.newColor=newColor;
return this.newColor;
}
constructor({newColor=‘green‘}={}){
this.newColor=newColor;
}
}
const freddie=new Chameleon({
newColor:‘purple‘
})
freddie.colorChange(‘orange‘)
function Person(firstName,lastName) {
this.firstName=firstName;
this.lastName=lastName;
}
const lydia=new Person(‘Lydia‘,‘Hallie‘);
const sarch=Person(‘Sarch‘,‘Smith‘);
console.log(lydia);
console.log(sarch);
部分题目参考:https://github.com/lydiahallie/javascript-questions/blob/master/zh-CN/README-zh_CN.md
原文链接:https://mp.weixin.qq.com/mp/homepage?__biz=MzI2NTQ5NTE4OA==&hid=7&sn=b6e703f14342dd6d416520b30bcb01f5&scene=25&uin=&key=&devicetype=Windows+10+x64&version=63020184&lang=zh_CN&ascene=1&session_us=gh_c36046921bbe&fontgear=1
标签:不包含 ase back 表示 syn lang foo 指定 erro
原文地址:https://www.cnblogs.com/jjgw/p/14676133.html