扫码关注官方订阅号
console.log(([][+[]]+[])[+!![]]) n //output
为什么这堆符号会输出n
业精于勤,荒于嬉;行成于思,毁于随。
拆解一下
> [] [] > +[] 0 > [][0] undefined > [][+[]] undefined > undefined+[] 'undefined' > [][+[]]+[] 'undefined' > ![] false > !![] true > +!![] 1 > 'undefined'[1] 'n' > ([][+[]]+[])[1] 'n' > ([][+[]]+[])[+!![]] 'n'
推荐你看下这篇文章 jother编码
([][+[]]+[])[+!![]]中先看最后一段[+!![]]![]为false,!![]为true,前面加上+变成整数,[+!![]]为1。 同理,[+[]]为0,但[][+[]]是undefined,+[]后仍是undefined。'undefined'[1],得出n。
([][+[]]+[])[+!![]]
[+!![]]
![]
!![]
[+[]]
[][+[]]
+[]
'undefined'[1]
无义务祭出 @justjavac 大大的神器: http://justjavac.com/javascript/2012/05/24/can-you-explain-why-10.html
另补充一副分解动作图:
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
拆解一下
推荐你看下这篇文章 jother编码
([][+[]]+[])[+!![]]
中先看最后一段[+!![]]
![]
为false,!![]
为true,前面加上+变成整数,[+!![]]
为1。同理,
[+[]]
为0,但[][+[]]
是undefined,+[]
后仍是undefined。'undefined'[1]
,得出n。无义务祭出 @justjavac 大大的神器: http://justjavac.com/javascript/2012/05/24/can-you-explain-why-10.html
另补充一副分解动作图: