Why does having [].map with curly brackets change the way it works?

后端 未结 4 1081
轮回少年
轮回少年 2021-01-23 02:15

So, basically I have this:

Array.prototype.toString = function() {
    return (\"[\" + this.map(thing => thing = \'\"\' + thing + \'\"\').join(\', \') + \"]\"         


        
4条回答
  •  情话喂你
    2021-01-23 02:53

    Without curly braces (or with regular curved brackets) it returns a single value straight up, whereas curly braces execute multiple lines of code. If you want this code to return a value you have to explicitly return it within those curly braces.

提交回复
热议问题