开发者

Why does alert(["a","b","c","d","e"][[1,2],3,4]) output e in javascript?

开发者 https://www.devze.com 2023-04-02 07:04 出处:网络
Could someone tell me why: alert([\"a\",\"b\",\"c\",\"d\",\"e\"][[1,2],3,4]) o开发者_如何学JAVAutputs e in JavaScript?Because comma is an operator that executes all of the separated instructions (

Could someone tell me why:

alert(["a","b","c","d","e"][[1,2],3,4]) 

o开发者_如何学JAVAutputs e in JavaScript?


Because comma is an operator that executes all of the separated instructions (in fact: two instructions, each of which can also use a comma operator) and returns the results of the last one. I.e.:

["a","b","c","d","e"][[1,2],3,4] => ["a","b","c","d","e"][4] === "e"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号