- Labels
- Semicolons
- Coercions
- Comparisons
- Inequalities
- Calculus
- Conditional statements
- Destructuring assignment
void
operatortypeof
operator,
operatortry-catch
statement- Hoisting
- Scopes & Closures & Hoisting
- Context
delete
operator...
operatorinstanceof
operator- Template literals
Object
Function
- Default parameters
arguments
class
GeneratorFunction
Promise
AsyncFunction
Reflect
Proxy
Array
Date
RegExp
Symbol
String
Number
Boolean
Math
Window
- Event loop
eval
methodwith
operator- Miscellaneous
vars: var vars = vars;
vars;
foo: { foo = 123 };
foo;
var foo = {};
var bar = 1;
foo: {
bar: 2;
baz: ++bar;
};
foo.baz + foo.bar + bar;
a: b: c: d: e: f: g: 1, 2, 3, 4, 5;
(printing => {
printing: {
console.log(1);
if (!printing) {
break printing;
}
console.log(2);
};
console.log(3);
})(false);
var foo = [] // Missing semicolon!
(new Date).getTime();
!function(){console.log('Awesome');}() // Missing semicolon!
!function(){console.log('JS');}();
var [foo, bar, baz] = [1, 2, 3];
foo = bar // Missing semicolon!
++baz
[foo, bar, baz];
function foo() {
return // Missing semicolon!
'Awesome JS';
}
foo() === 'Awesome JS';
var bar = 'bar' // Missing semicolon!
/JS/g.exec('Awesome JS');
!!~1;
false % 1;
1 / '';
+' -12';
+'1 2';
+'1'++;
'1' - - '1';
'5' + + '6';
'1' + 2 + '3' + 4;
'foo' + + 'bar';
4 - '5' + 0xf - '1e1';
!!!function() {};
4 + 3 + 2 + '1';
[1] + 1;
[] + 24 + 10;
'foo'.split('') + [];
[] + [] + 'foo'.split('');
[1, 2] + [3, 4];
[1, 2, [3, 4]] + [[5, 6], 7, 8];
[4] * [4];
({} + {});
[] + {};
[] * {};
{} + [];
[] + [];
++[];
[] + null + 1;
[4, 4] * [4, 4];
[3 + NaN + true] + [10 / (8 * null) - 1];
[][[]];
[[]][0];
++[[]][+[]];
'3' - 2 === 1;
undefined == false;
[1] == true;
var x = true;
var y = false;
x != y === !(x == y);
!!'false' == !!'true';
!!'false' === !!'true';
1 + 2 + '3' == 1 + '2' + 3;
'001' == true;
[2] == true;
'00' == 0;
[true] == true;
0 === -0;
null == 0;
[1, 1] == true;
' \t\r\n' == 0;
'0x0' == false;
[[[[1]]]] == true;
'002' == true;
[] == ![];
[[]] == 0;
10 > 9 > 8;
9 < 5 < 1;
2 < 6 < 1;
1 < 3 < 4;
+0 < -0;
01 < 1;
0,0000008 < 8;
[10] < [2];
'10' < '9';
'3' > '12'
'03' > '12';
Infinity > -Infinity;
({} + 'y' > {} + 'x');
0.3 - 0.1;
0.1 * 0.2;
.1 + .2 != .3;
0.1 + (0.2 + 0.3) == (0.1 + 0.2) + 0.3;
(0.2 + 0.4) / 1 == (0.1 + 0.2) * 2;
-9 % 7;
42 / -0;
9999999999999999 === 1e16;
1e16 === 1e16 + 1;
1e16 + 1.1 < 1e16 + 2;
var x = 5;
var y = 10;
var z = x+++y;
[x, y, z];
var x = 0;
[x+++x++, x];
1 + - + + + - + 1;
01 - + - 02 - + - 03;
8 | 1;
~~(-5.5);
~~+'2.9'-1 == ('2.9' >> 0) - 1;
(1.22e-10).toFixed(2);
12..toFixed(1);
(0.9).toFixed(0);
(0.00008).toFixed(3) === 0;
parseInt('08');
parseInt(null);
parseInt(null, 24);
parseInt(Infinity);
parseInt(1 / 0, 19);
parseInt('Infinity', 23)
parseFloat('12.3.4');
parseFloat('\t\v\r12.34\n ');
parseFloat('-.00');
('false') && ('bar');
1 || 'foo' && 0;
1 && 3;
1 && 'foo' || 0;
var x, y;
x = (y = 0) && (y = 1);
[x, y];
var x = 1;
if (false)
x = 3;
x = 4;
x;
var foo = NaN;
switch (foo) {
case NaN:
console.log('NaN');
break;
default:
console.log('default');
}
var foo = {};
switch (foo) {
case {}:
console.log('object');
break;
default:
console.log('default');
}
var [x] = [];
x;
var [x = 1] = [];
x;
var [x, x, x, x] = 'JS is awesome language'.split(' ');
x;
({ x, y } = { x: 5, y: 6, x: 7 });
var { x, y } = { x: x, y: y };
[x, y];
var x, { x: y = 1 } = { x };
[x, y];
var o1 = { a: 1 },
o2 = { b: 2 },
o3 = { c: 3 }
[o1, o2, o3] = [o3, o2, o1];
o3;
(() => void (1 + 1))();
void function() { return 'foo'; }();
typeof 000;
typeof (null && false);
typeof (void null);
typeof { null: null }.null;
typeof setTimeout(() => {}, 0);
typeof typeof undefined;
var y = 1, x = y = typeof x;
x;
var x = [typeof x, typeof y][1];
typeof typeof x;
(1, 2, 3);
var x = 0;
var y = (x++, 99);
[x, y];
(1, function(){})();
if (9, 0) console.log('ok');
[true, false][+true, +false];
(1,5 - 1) * 2;
var smth = (45, 87) > (195, 3) ? 'bar' : (54, 65) > (1, 0) ? '' : 'baz';
alert('1', alert('2', alert('3')));
typeof ('x', 3);
var f = (function f() { return '1' }, function g() { return 2 })();
typeof f;
[3, 4, 5, 6][1, 2];
if ((1, true) && (2, false) || (3, false) && (4, true) || (5, true)) {
console.log('if');
} else {
console.log('else');
}
alert('2',
foo = (x) => alert(x),
foo('1')
),
foo('3');
(() => {
try {
return 'try';
} finally {
console.log('finally');
}
})();
var foo = () => {
var o = { foo: 24 };
window.bar = () => {
return o;
};
try {
return o;
} finally {
o = null;
}
};
foo(); // => ?
bar(); // => ?
try {
setTimeout(function() {
throw new Error()
}, 1000);
} catch (err) {}
try {
try {
throw new Error('try');
} catch (err) {
console.error('inner', err.message);
throw err;
} finally {
console.log('finally');
}
} catch (err) {
console.error('outer', err.message);
}
(() => {
label: try {
return 0;
} finally {
break label;
return 1;
}
return 2;
})();
(() => {
try {
throw new Error('try')
} catch (err) {
throw err;
} finally {
throw new Error('finally');
}
})();
var bar;
f();
function f() {
return bar;
}
var bar = 2410;
(function() {
console.log(x);
console.log(f());
var x = 1;
function f() {
return 2;
}
})();
function f(x) {
return x * 2;
}
var f;
typeof f;
var x = 1;
{
var x = 2;
}
x;
if (!('y' in window)) {
var y = 1;
}
y;
(function() {
var x = x = 3;
})();
[typeof x, typeof y];
var foo = function bar() {
return 'bar';
}
typeof bar();
var foo = 1;
function bar() {
foo = 10;
return;
function foo() {};
}
bar();
foo;
x = 1;
(() => {
return x;
var x = 2;
})();
var x = 1;
if (function f() {}) {
x += typeof f;
}
x;
(function f() {
function f() { return 1; }
return f();
function f() { return 2; }
})();
for (var i = 0; i < 10; i++) {
setTimeout(() => alert(i), 100);
}
var foo = 11;
function bar() {
return foo;
foo = 10;
function foo() {};
var foo = '12';
}
typeof bar();
var foo = 1,
var bar = function foo(x) {
x && foo(--x);
};
foo;
(function() {
var foo = 'x';
(function (foo) {
foo = 'y';
})(foo);
return foo;
})();
(function f(f) {
return typeof f();
})(() => 1);
function f() {
var x = 5;
return new Function('y', 'return x + y');
}
f()(1);
var x = 1;
function f() {
var x = 2;
return new Function('', 'return x');
}
f()();
function f() {
alert(this);
}
f.call(null);
function f() {
return this;
}
f.call(f);
(function() {
var f = function() {
return this * 2;
};
return [
f.call(undefined),
f.call(null),
f.call(1)
];
})();
var user = {
name: 'Alex',
_user: this
};
user._user.name;
var foo = {
bar() { return this.baz },
baz: 1
};
typeof (f = foo.bar)();
(function() {
'use strict'
var x = 10;
var foo = {
x: 20,
bar() {
var x = 30;
return this.x;
}
};
return [
foo.bar(),
(foo.bar)(),
(foo.bar = foo.bar)(),
(foo.bar, foo.bar)(),
(foo.baz || foo.bar)()
];
})();
var foo = {
bar: function() { return this === foo },
baz: () => this === foo
};
foo.bar() === foo.baz();
var foo = {
bar: 'bar',
baz: !(function() {
console.log(this.bar);
})()
};
foo.baz;
(function() {
'use strict';
const g1 = (function() { return this || (1, eval)('this') })();
const g2 = (function() { return this })();
return g1 === g2;
}());
var numbers = [2, 3, 5, 7, 11, 13];
delete numbers[3];
numbers.length;
delete [].length;
function foo() {};
delete foo.length;
typeof foo.length;
var Person = function() {};
Person.prototype.type = 'person';
var admin = new Person();
delete admin.type;
admin.type;
delete delete window.document;
(function() {
x = 1;
window.y = 2;
this.z = 3;
var w = 4;
delete x;
delete y;
delete z;
delete w;
return [typeof x, typeof y, typeof z, typeof w];
})();
(x => {
delete x;
return x;
})(1);
var x = 1;
y = 1;
(function() {
return (delete window.x) === (delete window.y);
})();
void typeof delete this;
[...[...'...']].length
var foo = [...[,,24]];
[0 in foo, 1 in foo, 2 in foo];
function A() {};
function B() {};
A.prototype = B.prototype = {};
var a = new A();
a instanceof B;
function A() {};
var a = new A();
A.prototype = {};
a instanceof A;
function A() {};
function B() {};
B.prototype = Object.create(A.prototype);
var b = new B();
b instanceof A;
function f() { return f; }
new f() instanceof f;
`${1.0}`;
`use strict`;
this == null;
typeof `${{Object}}`.prototype
((...args) => args)``
var foo = { `hello world`: 24 };
Object instanceof Function;
Object.prototype.toString.call();
Object.prototype.toString.call(Object);
Object.is(NaN, NaN);
Object.is(-0, +0);
Object.assign({}, 'function');
var foo = 'abc';
var bar = Object(foo);
Object.prototype.toString.call(bar);
Object.freeze(window);
var didItWork = true;
didItWork;
({ 'toString': null }).propertyIsEnumerable('toString');
{ x: 1, y: 2 }['x'];
var obj = {
'': ''
};
obj[''];
{ [{}]: {} };
var obj = {
1: 'foo'
};
obj[1] == obj[[1]];
obj[[1]] == obj['1'];
'foo'.someProperty = 17;
'foo'.someProperty;
(function() {
var foo = {};
var bar = {};
var map = {};
map[foo] = 'foo';
map[bar] = 'bar';
return map[foo];
})();
100['toString']['length'];
({}).valueOf();
{ valueOf: () => true } == '1.0e0';
var foo = {
toString: () => '[object Foo]',
valueOf: () => 2410
};
'object: ' + foo;
var x = 1;
var y = { toString: () => '1' };
var z = 1;
x + y + z;
var foo = { x: 1 };
foo.y = foo = { x: 2 };
foo.y;
var t = true;
var obj = ({[t]: t});
obj;
var t = true;
var obj = ({[`${t}`]: t, [t]: t});
obj;
('__proto__').__proto__.__proto__.__proto__;
var proto = {
x: () => 'x'
}
var foo = new Object(proto);
var bar = new Object(proto);
foo === bar;
Object.create(null) instanceof Object;
var bar = { bar: 'bar'};
function foo() {}
foo.prototype = bar;
[bar instanceof foo, Object.create(bar) instanceof foo];
Object.prototype.isPrototypeOf(window);
var foo = { __proto__: null };
Object.getPrototypeOf(foo) === null;
var __proto__ = 'bar';
var foo = { __proto__ };
Object.getPrototypeOf(foo) === Object.prototype;
typeof Function;
Function instanceof Function;
Function instanceof Object;
typeof Function.prototype;
Function.prototype instanceof Function;
Function.prototype.isPrototypeOf(Function);
Function.prototype.prototype;
Function.prototype === Function;
Function.prototype.constructor === Function;
(function (x, y) {}).length;
(function (foo) {
return typeof foo.bar;
})({ foo: { bar: 1 } });
var f = () => { x: 1 };
f();
function f() {};
f.bind(this).name;
var f = function() {};
var g = f.bind();
g.prototype;
function f(x, y) {
return x + y;
}
f.bind(1)();
function f() {
return this.value;
}
f.bind({ value: 1 }).call({ value: 2 });
var f = () => this;
var g = function() { return this }.bind(this);
f() === g();
function f() {}
var fBind = f.bind({});
var obj = new f();
[obj instanceof f, obj instanceof fBind];
function foo() {
return Function.bind(null, 'console.log(bar);');
}
var bar = 1;
(function() {
var bar = 2;
foo()()();
})();
(function() {
if (false) {
let f = { g() => 1 };
}
return typeof f;
})();
var foo = 2410;
var bar = ['a', 'b'];
var baz = { first: true };
function f(x, y, z) {
x = 3;
y.push('c');
y = ['c'];
z.first = false;
z = true;
}
f(foo, bar, baz);
[foo, bar, baz.first];
function f(name) {
this.name = name;
}
var name = 'foo';
var person = f('bar');
[name, person];
var x = 0;
function f() {
x++;
this.x = x;
return f;
}
var foo = new new f;
foo.x;
var c = 'constructor';
c[c][c]('console.log(c)')();
var f = Function.prototype.call;
f();
console.log.call.call.call.call.call.apply(x => x, [1, 2]);
function f(x = 24, y = 10) {
return x + y;
}
foo(undefined, 20);
foo(null, null);
function g(x, y = 24, z = 10) {
return x + y + z;
}
g(1,,2);
var bar = 1;
function f(bar = bar) {
return bar;
}
f();
var x = 1;
function f(y = function() { return x; }) {
var x = 2;
return y();
}
f();
function f(x, y = function() { return x; }) {
console.log(x);
var x = 1;
console.log(y());
}
f(2);
function f(x, y = function() { console.log(x); x = 1; }) {
var x;
console.log(x);
x = 2;
y();
console.log(x);
}
f(3);
(function() {
return typeof arguments;
})();
(function() {
return arguments.toString();
})();
(function() {
console.log(
arguments.constructor === {}.constructor,
arguments.constructor === [].constructor
);
})();
(function() {
var arguments;
return arguments[0];
})(200);
function f(x, y, z) {
arguments[2] = 10;
return z;
}
f(1, 2, 3);
(() => arguments.toString())();
function f(x, y) {
arguments[2] = 5;
return y;
}
f(1);
function f(foo, bar, baz) {
return Array.from(arguments);
}
f(...['foo', , 'bar']);
var g = function() {
return arguments;
};
g() == g();
var Foo = class {};
class Foo {};
class AwesomeJS extends null {};
new AwesomeJS;
typeof (new (class F extends (String, Array) {})).substring;
typeof (new (class { class () {} }));
(function() {
let f = this ? class g {} : class h {};
return [
typeof f,
typeof h
];
})();
class A {
foo() {
console.log('A.foo');
}
}
class B extends A {
foo() {
super.foo();
}
}
class C {
foo() {
console.log('C.foo');
}
}
var D = {
foo: B.prototype.foo,
};
Object.setPrototypeOf(B, C.constructor);
D.foo();
function* g() {
yield 'foo';
}
g[Symbol.toStringTag] === g()[Symbol.toStringTag];
function* g() {
yield 'foo';
yield yield 'bar';
yield yield yield 'baz';
}
var gen = g();
[...gen];
(function* f() { yield f })().next()
typeof Promise.resolve(2410);
Promise.reject(Promise.resolve());
new Promise((resolve, reject) => resolve(24))
.then((res) => console.log(res))
.then((res) => console.log(res));
Promise.resolve('foo')
.then(Promise.resolve('bar'))
.then((res) => console.log(res));
Promise.resolve('foo')
.then((res) => Promise.resolve('bar'))
.then((res) => console.log(res));
Promise.resolve(2)
.then(3)
.then((res) => console.log(res));
Promise.resolve({ x: 24 })
.then((res) => delete res.x)
.then((res) => console.log(res.x));
Promise.resolve(2410).then(
(res) => { throw new Error(res) },
(err) => { try {} catch(err) {} }
);
Promise.reject(24)
.then(null, null)
.then(null, (reason) => console.log(reason));
Promise.reject(24)
.then(10, null)
.then(null, (reason) => console.log(reason));
Promise.reject(24)
.then(null, 10)
.then(null, (reason) => console.log(reason));
Promise.resolve(24)
.then(null, null)
.then((res) => console.log(res), null);
Promise.resolve(24)
.then(null, 10)
.then((res) => console.log(res), null);
Promise.resolve(24)
.then(10, null)
.then((res) => console.log(res), null);
async function f(x) {
return x * x;
}
f(2) === 4;
var y = 2;
async function f(x = await y) {
return x * x;
}
f();
(() => {
'use strict';
async function eval(x, y) {
await x * y;
}
eval(1, 2);
})();
async function f(x) {
return await x * (await x);
}
f(2).then(res => console.log(res));
async function User(firstname, lastname) {
this.firstname = await firstname;
this.lastname = await lastname;
}
var user = new User('John', 'Doe');
(async function(){}).__proto__.__proto__ == (function(){}).__proto__;
Reflect.get(Reflect, Reflect.get(Reflect, 'get').name);
Reflect.setPrototypeOf(Reflect, Array.prototype);
typeof Reflect.slice;
Reflect.preventExtensions(Reflect);
Reflect.isExtensible(Reflect);
var proxy = new Proxy({}, {});
proxy instanceof Proxy;
(() => {
Proxy.prototype = null;
class P extends Proxy {
constructor() {
super(window, {});
this.foo = 'foo';
}
};
new P;
console.log(window.foo);
})();
(() => {
Proxy.prototype = null;
class P extends Proxy {
constructor() {
super(window, {
getPrototypeOf() { return P.prototype }
});
}
};
console.log((new P) instanceof P === true);
})();
[].valueOf();
typeof [1, 2, 3];
var arr = [];
arr[1] = 1;
arr[24] = 24;
arr.length;
var arr = [];
var i = 3;
arr[--i] = ++i;
arr;
[].length = -2;
[,].length;
[,,].length;
[[[1], 2], 3].length;
new Array(null);
new Array(1)[0] + '';
new Array('100').length;
new Array(1, 2) == true;
new Array([], null, undefined, null) == ',,,';
var arr = new Array(3);
arr.map((value, index) => index);
[1, 2, 3].toString();
[1, 2, 3, 4, 5][0..toString().length];
[].unshift(0);
var arr = [2, 3, 5, 7, 11];
arr.indexOf(7, 2);
arr.indexOf(2, -3);
[NaN].indexOf(NaN);
'0'.split(void 0, 0);
Array(2).join();
[1, 2].join(undefined);
[,,,].join() === ',,';
Array(4).join('js!' - 4);
Array(5).join(',').length;
[].concat[1, 2, 3];
[].fill.call({ length: 3 }, 4);
Array.from({ '': '' });
[NaN].includes(NaN);
var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
arr.slice();
arr.slice(-2);
arr.slice(3, -6);
[1, 2, 3].slice(0, null);
Array(3).map(item => 'x');
Array.apply(null, new Array(4)).map((el, i) => i);
Array.apply(null, { length : 3 });
[...new Set([1, 1, 2, 3, 5, 8, 13])];
var arr = [1, 2, 3];
var pushResult = arr.push(4, 5, 6);
[pushResult, arr];
var arr = [undefined, , true];
arr.filter(() => true);
var arr = new Array(2);
var i = 0;
arr.forEach(() => i++);
i;
var arr = [80, 9, 34, 23, 5, 1];
arr.sort(); // => ?
new Array(10).map((el, i) => i + 1);
var bag = new Array(3).fill([]);
bag[0].push(1);
bag[1].push(1);
bag; // => ?
Array.isArray({
constructor: Array,
length: 0,
__proto__: Array.prototype,
});
Array.prototype.push(1, 2, 3);
Array.prototype[1] = 'foo';
var arr = [undefined, ,];
0 in arr; // => ?
1 in arr; // => ?
arr.hasOwnProperty(1); // => ?
new Date(undefined);
new Date(null);
'2016/12/31' == new Date('2016/12/31');
typeof (new Date() + new Date());
new Date(-666).getUTCMonth();
new Date(0) - 0;
new Date(0);
new Date('0');
new Date(0, 0);
new Date(0, 0, 0);
var f = Date.bind.call(Date, 2000, 0, 1);
var g = Function.bind.call(Date, null, 2000, 0, 1);
new f().toString() === new g().toString();
/[a-z]/ === /[a-z]/;
RegExp.prototype.toString = function() {
return this.source;
}
/3/3/ - /1/;
(() => {
class CustomRegExp extends RegExp {
constructor() {
super();
}
}
return new CustomRegExp;
})();
'foobar'.replace(/^/, "$'");
/foo.bar/.test('foo\nbar');
/^$/.test('');
/$^/.test('');
/^.$/.test('');
/^..$/.test('');
'xy'.split(/x*?/);
'xy'.split(/(?:xy)*/);
'xy'.split(/x*/);
'.'.split(/(.?)(.?)/);
'.'.split(/()()/);
''.split(/.?/);
'test'.split(/(?:)/, -1);
typeof (/()??/).exec('')[1];
/^$^$^$^$^$^$$$$^^^/.test('');
new RegExp(/xy+z/, 'i');
new RegExp([].join('|'));
var foo = /[/ + 'javascript'[0] + '///';
foo;
var bar = /\[/ + 'javascript'[0] + '///';
bar;
var foo = new Symbol();
Symbol('foo') === Symbol('foo');
class MySymbol extends Symbol {
constructor() {
super();
}
}
var symbol = new MySymbol();
Symbol.for('bar') === Symbol.for('bar');
Symbol.keyFor(Symbol.iterator);
var obj = {
[Symbol('foo')]: 'foo',
[Symbol('bar')]: 'bar'
};
Object.keys(obj);
var obj = {};
obj[Symbol('foo')] = true;
obj[Symbol('foo')] = false;
Object.getOwnPropertySymbols(obj).length;
String(1.23e+2);
String(['foo', 'bar']);
'' instanceof String;
'foo' == new function() { return String('foo') };
'foo'[-1] == 'foo'.charAt(-1);
'foo'.charAt(1) === 'foo'.substring(1, 2);
++'24'.split('')[0];
3 instanceof Number;
Number.MAX_VALUE > 0;
Number.MIN_VALUE > 0;
Number();
Number(undefined);
Number('');
Number([]);
Number([24, 10]);
Number({});
Number.isNaN('NaN') === window.isNaN('NaN');
Number('0.') === Number('.0');
Number.prototype.compare = function(value) {
return this === value;
};
Number(123).compare(123);
Number.prototype.toString = function() {
return typeof this;
};
(4).toString();
Boolean('true') === true;
Boolean([]);
Boolean('000');
Boolean(-Infinity);
if (new Boolean(false)) {
console.log('Awesome JS');
}
new Boolean('').valueOf();
new Boolean(false).valueOf() === false;
Math instanceof Math;
Math.round(true + .501);
Math.round(-5.5);
Math.ceil(5.01) === -Math.floor(-5.01);
Math.max(2, []);
Math.max({}, 2);
Math.max() > Math.min();
Math.pow(+0, -1);
Math.pow(2, 53) === Math.pow(2, 53) + 1;
Math.pow(-0, -1);
typeof window;
typeof Window;
Object.getPrototypeOf(window) === Window;
Window.constructor === Function;
Window.prototype.constructor === Window;
(() => {
console.log(window);
var window = window;
})();
setTimeout(() => console.log(1), 1);
setTimeout(() => console.log(2), 1000);
setTimeout(() => console.log(3), 0);
console.log(4);
setTimeout(() => {
console.log(1);
setTimeout(() => console.log(2), 0);
}, 500);
setTimeout(() => {
setTimeout(() => console.log(3), 500);
}, 250);
new Promise((resolve, reject) => {
console.log(1);
resolve();
}).then(() => {
console.log(2);
});
console.log(3);
setTimeout(() => {
console.log(1);
}, 300);
Promise.resolve()
.then(() => console.log(2));
console.log(3);
setTimeout(() => {
console.log(1);
}, 0);
Promise.resolve(2)
.then((res) => {
console.log(res);
setTimeout(() => {
console.log(3);
}, 0);
return Promise.resolve(4);
})
.then((res) => {
console.log(res);
});
async function f() {
console.log(await new Promise(resolve => {
setTimeout(() => resolve(2), 0);
}));
}
console.log(1);
f();
console.log(3);
// Node.js
setTimeout(() => {
console.log(1);
}, 1000);
process.nextTick(() => {
console.log(2);
});
console.log(3);
// Node.js
process.nextTick(() => {
console.log(1);
while (true) {}
});
process.nextTick(() => {
console.log(2);
});
function foo() {
return eval.bind(null, '(function() { return bar; })');
}
var bar = 1;
(function() {
var bar = 2;
foo()()(); // => ?
})();
function foo() {
return '(function() { return bar; })';
}
var bar = 1;
(function() {
var bar = 2;
eval(foo())(); // => ?
})();
var a = 1;
var obj = {
b: 2
};
with (obj) {
var b;
console.log(a + b); // => ?
}
with ({ a: 1 }) {
a = 2,
b = 3
}
[window.a, window.b];
with (function (x, undefined) {}) {
length; // => ?
}
({
x: 10,
foo() {
function bar() {
console.log(x); // => ?
console.log(y); // => ?
console.log(this.x); // => ?
}
with (this) {
var x = 20;
var y = 30;
bar.call(this);
}
}
}).foo();
var foo = { bar: 'baz' && 'foobarbaz' };
with (foo) var bar = eval('bar, 24');
foo.bar;
(![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]];
({[{}]:{[{}]:{}}})[{}][{}];
(function pewpew(Infinity, length, __proto__) {
return [,,~0.[0|0]][pewpew.__proto__.length && Infinity,
-~String(this).length >> __proto__] << (0. === .0) + Infinity;
}).apply(typeof pewpew, [,,2]);