How to solve the + + [[]] [+ []] + [+ []] = 10 problem of javascript
This article mainly explains "how to solve the javascript + [[]] [+ []] + [+ []] = 10 problem". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to solve the "javascript + [[]] [+ []] + [+ []] = 10 problem"!
This is a Javascript language problem, a completely valid equation, if you don't believe in yourself, you can try it. Let's take a look at the answer of the master:
+ [[]] [+ []] + [+ []]
If you split this expression, it is equal to:
+ [[]] [+ []] + [+ []]
In JavaScript, + [] = 0 is exactly right. + converts some characters into numbers, where the formula becomes + "" or 0.
Therefore, we can simplify (+ has a higher priority than +):
+ [[]] [0] + [0]
Because [[]] [0] means: get the first element of [[]], this results in the following result:
[[]] [0] returns an internal array ([]). According to the language specification, we say that [[]] [0] = [] is incorrect, but let's call this internal array A to avoid misspelling.
+ [[]] [0] = A + 1, because + + means "plus one".
+ [[]] [0] = = + (A + 1); in other words, what you get is always a number (+ 1 does not necessarily get a number, but + must be).
Similarly, we can simplify this pile of code more clearly. Let's change A back to []:
+ ([] + 1) + [0]
In JavaScript, this is also true: [] + 1 = = "1" because [] = = "" (which is equivalent to a join of the internal elements of an empty array), so:
+ ([] + 1) = = ("" + 1), and + ("+ 1) = = + (" 1 ") and + (" 1 ") = 1
Let's simplify again:
1 + [0]
Again, in Javascript, this is true: [0] = "0", because this is equivalent to a join of internal elements of an array with one element. The elements will be used to separate. When there is only one element, you can infer that the result of the process is its own first element.
So, finally we get (number + string = string):
1 + "0" = = "10" / / Yay! Thank you for your reading, the above is "javascript + [[]] [+ []] + [+ []] = 10 problem how to solve the content, after the study of this article, I believe you on the javascript + [[]] [+ []] + [+ []] = 10 problem how to solve this problem has a deeper understanding, the specific use of the situation also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!