JS奇淫技巧：数值的七种写法

JS奇淫技巧：挑战前端黑科技，数值的七种写法，能全看懂的一定是高手

var a = 1;

## 第二种写法：

var a= +!!{};

console.log(a);

2=(+!!{})+(!!{})

3=(+!!{})+(!!{})+(!!{})

111=+((+!!{})+[]+(+!!{})+(+!!{}))

## 第三种写法：

var a=266119^266118;

console.log(a);

var a=596219^596218;

var a=115812^115813;

## 第四种写法：

var a = function (s, h) {

return s ^ h;

}(719028, 719029);

console.log(a);

## 第五种写法：

var a = ast({"type":"File","program":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"BinaryExpression","left":{"type":"NumericLiteral","value":115812},"operator":"^","right":{"type":"NumericLiteral","value":115813}}}]}});

console.log(a);

function ast(node) {

if(node.type == "File"){

return ast_excute(node.program);

}

if(node.type == "Program"){

return ast_excute(node.body[0]);

}

if(node.type == "ExpressionStatement"){

return ast_excute(node.expression);

}

if(node.type == "BinaryExpression"){

var left_value = node.left.value;

var right_value = node.right.value;

var operator = node.operator;

if(operator == "^"){

return left_value ^ right_value;

}

}

}

## 第六种写法

Eval的使用。

var a = eval（1);

console.log(a);

Eval的变形写法：

var a = window[(14).toString(32)+(31).toString(32)+(10).toString(32)+(21).toString(32)](1); console.log(a);

var a = function (s, h) {

return eval（String.fromCharCode(115, 32, 94, 32, 104));

}(678405, 678404);

console.log(a);

## 第七种写法：

var a = [].constructor.constructor("return 1")();

console.log(a);

var a = [].constructor.constructor("\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u0031")();

console.log(a);

var a = []["\u0063\u006f\u006e\u0073\u0074\u0072\u0075\u0063\u0074\u006f\u0072"]["\u0063\u006f\u006e\u0073\u0074\u0072\u0075\u0063\u0074\u006f\u0072"]("\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u0031")();

console.log(a);

var \$ = ["\u0061", "\u0062", "\u0063", "\u0064", "\u0065", "\u0066", "\u0067", "\u0068", "\u0069", "\u006a", "\u006b", "\u006c", "\u006d", "\u006e", "\u006f", "\u0070", "\u0071", "\u0072", "\u0073", "\u0074", "\u0075", "\u0076", "\u0077", "\u0078", "\u0079", "\u007a", "\u0028", "\u0029", "\u0027", "\u0022", "\u005b", "\u005d", "\u002e"];

var a = [][\$[443650 ^ 443648] + \$[169829 ^ 169835] + \$[338738 ^ 338751] + \$[745099 ^ 745113] + \$[847761 ^ 847746] + \$[986395 ^ 986378] + \$[591407 ^ 591419] + \$[989467 ^ 989465] + \$[820242 ^ 820225] + \$[848420 ^ 848426] + \$[782593 ^ 782608]][\$[972307 ^ 972305] + \$[406834 ^ 406844] + \$[838220 ^ 838209] + \$[317151 ^ 317133] + \$[799896 ^ 799883] + \$[655841 ^ 655856] + \$[333562 ^ 333550] + \$[745730 ^ 745728] + \$[843076 ^ 843095] + \$[151776 ^ 151790] + \$[832229 ^ 832244]]("\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u0031")();

console.log(a);

[][\$[443650 ^ 443648] + \$[169829 ^ 169835] + \$[338738 ^ 338751] + \$[745099 ^ 745113] + \$[847761 ^ 847746] + \$[986395 ^ 986378] + \$[591407 ^ 591419] + \$[989467 ^ 989465] + \$[820242 ^ 820225] + \$[848420 ^ 848426] + \$[782593 ^ 782608]][\$[972307 ^ 972305] + \$[406834 ^ 406844] + \$[838220 ^ 838209] + \$[317151 ^ 317133] + \$[799896 ^ 799883] + \$[655841 ^ 655856] + \$[333562 ^ 333550] + \$[745730 ^ 745728] + \$[843076 ^ 843095] + \$[151776 ^ 151790] + \$[832229 ^ 832244]]("\u0072\u0065\u0074\u0075\u0072\u006e\u0020\u0031")();