User:Hakerh400/JavaScript Quiz
Jump to navigation
Jump to search
In this article I post some JavaScript snippets whose behavior may be hard to predict. If you think you know JavaScript, try to guess what each of these snippets outputs before running it.
001
0..constructor.prototype[Symbol.iterator] = a=>({next:b=>({done:1})}); let Array = [1, 2, ... 10]; let n = ~new Array.length.constructor(Array.length); console.log(n);
002
function *a(){ console.log('entry'); return(yield yield)(yield yield); } const b = a().next.bind(a()); const c = () => ~setTimeout(() => console.log(typeof b(c).value)); for(let i = 0; i !== 5; i++) c();
003
console.log([ a = a => b => a + b, b = a.call, c = b.bind(b), ].reduce(c));
004
console.log([ a = (a=>(b=>b(b))(b=>c=>c?(a+=c,b(b)):a))(0), b = a.call, c = b.bind(b), ...a+a(), ].reduce(c)(0));
005
(([u0061])=>\u0061)({*[Symbol.iterator](){[a=5]=[,a=7]}})
006
((a,b)=>a(a(b)).length)(eval,(a=>a+((a,b)=>a(a,b))((a,[b,...c],d=[])=>b?a(a,c)+b:d,a))(`"'n\\`))
007
((a,b)=>b^=~a(a,b))((a,[b,...c],d=c[1])=>d?a(a,c):b,[a=>a,a=>b=>a,a=>(b=[a1=>a2])=>a1(a2)].reduce(function*(a,b){return a+b}).next().value)