// 注意,在Chrome浏览器中打印
[[][0] + []][0][5]+[[][[[][0] + []][0][4]+[[][0] + []][0][5]+[[][0] + []][0][1]+[[][0] + []][0][2]] + []][0][8]+[[[] == []][0] + []][0][2]+[[][[[][0] + []][0][4]+[[][0] + []][0][5]+[[][0] + []][0][1]+[[][0] + []][0][2]] + []][0][6]+[[][[[][0] + []][0][4]+[[][0] + []][0][5]+[[][0] + []][0][1]+[[][0] + []][0][2]]+[]][0][23]+[[][0] + []][0][3]+[[][[[][0] + []][0][4]+[[][0] + []][0][5]+[[][0] + []][0][1]+[[][0] + []][0][2]] + []][0][8]+[+[1 + [[][0] + []][0][3] +309][0] + []][0][7]+[[][[[][0] + []][0][4]+[[][0] + []][0][5]+[[][0] + []][0][1]+[[][0] + []][0][2]] + []][0][6]+[[][0] + []][0][0]
//执行完的结果很神奇的是一段话
//"i love you"
亲测了一下,不得不感叹js的神奇,于是去探究其中的原理,就会发现充分运用了JavaScript 隐式类型转换原理。
可以任意输出数字
let zero = +[];//0
let one = +(![]==![]);//1
let two = +(![]==![])+(![]==![]);//one+one=2
let three = +(![]==![])+(![]==![])+(![]==![]);//one+one+one=3
let four = +(![]==![])+(![]==![])+(![]==![])+(![]==![]);//one+one+one+one+one=4
let five = +(![]==![])+(![]==![])+(![]==![])+(![]==![])+(![]==![]);//one+one+one+one+one=5
let ten = +(+(![]==![])+[]+(+[]));//10
let hundred = +(+(![]==![])+[]+(+[]))*+(+(![]==![])+[]+(+[]));//ten*ten=100
let thousand = +(+(![]==![])+[]+(+[]))*+(+(![]==![])+[]+(+[]))*+(+(![]==![])+[]+(+[]));//ten*hundred=1000
最初的字母来源
let voidStr = []+[];
//""
let trueStr = (![]==![])+[];
//"true"
let falseStr = ([]==[])+[];
//"false"
let undefinedStr = [][+[]]+[];
//"undefined"
let nanStr = +[][+[]]+[];
//"NaN"
//["true"][0][3]获得字母e
Infinity
//[]+one+[trueStr][zero][three]+three+zero+(ten-one) = "1e309"
let InfinityNum = []+(+(![]==![]))+[(![]==![])+[]][+[]][+(![]==![])+(![]==![])+(![]==![])]+(+(![]==![])+(![]==![])+(![]==![]))+(+[])+(+(+(![]==![])+[]+(+[]))-(+(![]==![])));//"1e309"
//+("1e309")转成数字后,相当于 1 乘以 10 的 309 次方,大于 JavaScript 最大的数,所以结果会是 Infinity
//+(InfinityNum)+[]="Infinity"
let InfinityStr = +([]+(+(![]==![]))+[(![]==![])+[]][+[]][+(![]==![])+(![]==![])+(![]==![])]+(+(![]==![])+(![]==![])+(![]==![]))+(+[])+(+(+(![]==![])+[]+(+[]))-(+(![]==![]))))+[];
//"Infinity"
Function
//[]["find"]会显示数组的find函数,结果为:function find() { [native code] }
//[undefinedStr][zero][four]+[undefinedStr][zero][five]+[undefinedStr][zero][ten-four]+[undefinedStr][zero][two] = "find"
let funStr = [][ [[][+[]]+[]][+[]][+(![]==![])+(![]==![])+(![]==![])+(![]==![])] + [[][+[]]+[]][+[]][+(![]==![])+(![]==![])+(![]==![])+(![]==![])+(![]==![])] + [[][+[]]+[]][+[]][+(+(![]==![])+[]+(+[]))-(+(![]==![])+(![]==![])+(![]==![])+(![]==![]))] + [[][+[]]+[]][+[]][+(![]==![])+(![]==![])]]+[];
//"function find() { [native code] }"
constructor
//constructor 是一个神奇的属性,因为通过它,我们可以获得各种类型的值对象的构造函数!
//[funStr][zero][three]+[funStr][zero][ten-four]+[undefinedStr][zero][one]+[falseStr][zero][three]+[trueStr][zero][zero]+[trueStr][zero][one]+[trueStr][zero][two]+[funStr][zero][three]+[trueStr][zero][zero]+[funStr][zero][ten-four]+[trueStr][zero][one] = constructor
let constructorStr = [ [][ [[][+[]]+[]][+[]][+(![]==![])+(![]==![])+(![]==![])+(![]==![])] + [[][+[]]+[]][+[]][+(![]==![])+(![]==![])+(![]==![])+(![]==![])+(![]==![])] + [[][+[]]+[]][+[]][+(+(![]==![])+[]+(+[]))-(+(![]==![])+(![]==![])+(![]==![])+(![]==![]))] + [[][+[]]+[]][+[]][+(![]==![])+(![]==![])]]+[] ][+[]][+(![]==![])+(![]==![])+(![]==![])] +
[ [][ [[][+[]]+[]][+[]][+(![]==![])+(![]==![])+(![]==![])+(![]==![])] + [[][+[]]+[]][+[]][+(![]==![])+(![]==![])+(![]==![])+(![]==![])+(![]==![])] + [[][+[]]+[]][+[]][+(+(![]==![])+[]+(+[]))-(+(![]==![])+(![]==![])+(![]==![])+(![]==![]))] + [[][+[]]+[]][+[]][+(![]==![])+(![]==![])]]+[] ][+[]][ +(+(![]==![])+[]+(+[])) - (+(![]==![])+(![]==![])+(![]==![])+(![]==![])) ] +
[ [][+[]]+[] ][+[]][+(![]==![])] +
[ ([]==[])+[] ][+[]][+(![]==![])+(![]==![])+(![]==![])] +
[ (![]==![])+[] ][+[]][+[]] +
[ (![]==![])+[] ][+[]][+(![]==![])] +
[ (![]==![])+[] ][+[]][+(![]==![])+(![]==![])] +
[ [][ [[][+[]]+[]][+[]][+(![]==![])+(![]==![])+(![]==![])+(![]==![])] + [[][+[]]+[]][+[]][+(![]==![])+(![]==![])+(![]==![])+(![]==![])+(![]==![])] + [[][+[]]+[]][+[]][+(+(![]==![])+[]+(+[]))-(+(![]==![])+(![]==![])+(![]==![])+(![]==![]))] + [[][+[]]+[]][+[]][+(![]==![])+(![]==![])]]+[] ][+[]][+(![]==![])+(![]==![])+(![]==![])] +
[ (![]==![])+[] ][+[]][+[]] +
[ [][ [[][+[]]+[]][+[]][+(![]==![])+(![]==![])+(![]==![])+(![]==![])] + [[][+[]]+[]][+[]][+(![]==![])+(![]==![])+(![]==![])+(![]==![])+(![]==![])] + [[][+[]]+[]][+[]][+(+(![]==![])+[]+(+[]))-(+(![]==![])+(![]==![])+(![]==![])+(![]==![]))] + [[][+[]]+[]][+[]][+(![]==![])+(![]==![])]]+[] ][+[]][ +(+(![]==![])+[]+(+[])) - (+(![]==![])+(![]==![])+(![]==![])+(![]==![])) ] +
[ (![]==![])+[] ][+[]][+(![]==![])];
// "constructor"
//0["constructor"] => function Number() { [native code] } 可以获取字母m,g
toString
constructor 可是一个神奇的属性,因为通过它,我们可以获得各种类型的值对象的构造函数!
//0["constructor"] // function Number() { [native code] }
""["constructor"] // function String() { [native code] }
//"to" + ""["constructor"]["name"] => "toString"
toString 这个方法可以表示出 26个 字母!
NumberObject.toString(radix)
radix:表示数字的基数,使 2 ~ 36 之间的整数。若省略该参数,则使用基数 10。但是要注意,如果该参数是 10 以外的其他值,则 ECMAScript 标准允许实现返回任意值
10['toString'](36)
//a
35['toString'](36)
//Z