preface
Put a previous blog post code to print the beast.
Body: What is the output of the following magic code (just numbers and []) when I type it into the Console of the browser Console?
[+ (1 + [[] [0] + []] [0] [3] + 365] [0] + []] [0] [0] + [[], [[[] [0] + []] [0] [4] + [[] [0] + []] [0] [5] + [[] [0] + []] [0] [1] + [[0] + [] []] [0] [2]] + []] [0] [8] + [[[] = = []] of [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] + 365] [0] + []] [0] [7] + [[], [[[] [0] + []] [0] [4] + [[] [0] + []] [0] [5] + [[0] + [] []] [0] [1] + [[] [0] + []] [0] [2]] + []] [0] [6] + [[] [0] + []] [0] [0]Copy the code
Try it, and you’ll find it’s a standard lyrical expression.
Analysis of the
On a related note, there is a problem when learning about data types:
[] = =! [] [] [] = =Copy the code
The first sentence of these two sentences is true because! Precedence over ==, so first == right (! []) == = left side to the number 0, then == right side of the false also converted to 0, so equal; [] is a reference type, and the two [] points to different heap memory, so it is false. Refer to the link
I just remembered that this is a similar type conversion problem, so let’s go back to the discussion in this article. We need to statement individual strings and see how each string is retrieved
1. Get the I
1. Use I in ‘undefined’
[[] [0] + []] [0] [5]Copy the code
2. Take ‘Infinity’I
ori
[+ (1 + [[] [0] + []] [0] [3] + 365] + []] [0] [0]Copy the code
2. Get the l
[] == [] is false so it’s easy to get l,
[[[] = = []] of [0] + []] [0] [2]Copy the code
3. O
Function find() {[native code]} = function find() {[native code]} = function find() {[native code]} = function find() {[native code]} = function find() {[native code]} = function find() {[native code]} = function find() {
[[[0] + [] []] [0] [4] + [[] [0] + []] [0] [5] + [[] [0] + []] [0] [1] + [[] [0] + []] [0] [2]] / / output [' find '] [[], [[[0] + [] []] [0] [4] + [[] [0] + []] [0] [5] + [[] [0] + []] [0] [1] + [[] [0] + []] [0] [2]] + []] of [0] / / output function "the find () {} [native code]"Copy the code
So you enter the following string to get the string O
[[[[] [] [0] + []] [0] [4] + [[] [0] + []] [0] [5] + [[] [0] + []] [0] [1] + [[] [0] + []] [0] [2]] + []] [0] [6]Copy the code
4. Get v
As above, get v from “function find() {[native code]}” so enter the following string to get the string v
[[[[] [] [0] + []] [0] [4] + [[] [0] + []] [0] [5] + [[] [0] + []] [0] [1] + [[] [0] + []] [0] [2]] + []] [0] [23]Copy the code
5. E
You get e from ‘false’ or ‘undefined’
[[[] == []][0]+ []][0][4]
或者
[[][0]+[]][0][3]
Copy the code
6. Y
Take y from the ‘Infinity’ we just used
[+ (1 + [[] [0] + []] [0] [3] + 365] + []] [0] [7]
7. Get a second O
So let’s take the first o
[[[[] [] [0] + []] [0] [4] + [[] [0] + []] [0] [5] + [[] [0] + []] [0] [1] + [[] [0] + []] [0] [2]] + []] [0] [6]Copy the code
8. U
Function find() {[native code]}’ function find() {[native code]}
[[] [0] + []] [0] [0] or [[], [[[] [0] + []] [0] [4] + [[] [0] + []] [0] [5] + [[] [0] + []] [0] [1] + [[] [0] + []] [0] [2]] + []] [0] [1]Copy the code
9. Select a space at last
Get space from ‘function find() {[native code]}’
[[[[] [] [0] + []] [0] [4] + [[] [0] + []] [0] [5] + [[] [0] + []] [0] [1] + [[] [0] + []] [0] [2]] + []] [0] [8]Copy the code
10. Complete stitching
So at this point we’ve got all the strings we need for the whole sentence, which we can concatenate to make the whole statement
[+ (1 + [[] [0] + []] [0] [3] + 365] [0] + []] [0] [0] + [[], [[[] [0] + []] [0] [4] + [[] [0] + []] [0] [5] + [[] [0] + []] [0] [1] + [[0] + [] []] [0] [2]] + []] [0] [8] + [[[] = = []] of [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] + 365] [0] + []] [0] [7] + [[], [[[] [0] + []] [0] [4] + [[] [0] + []] [0] [5] + [[0] + [] []] [0] [1] + [[] [0] + []] [0] [2]] + []] [0] [6] + [[] [0] + []] [0] [0]Copy the code
Output I love you
conclusion
This sentence is of no use to a single person like me, nor is it actually useful in typing code. It’s better to simply say I love you. Having said that, the point of this article is not that this sentence is useful, but that js data types are really powerful and terrifically difficult, so it’s important to get the basics right.
Js soul of the ask (top) JS soul of the ask (middle) JS soul of the ask (bottom)
If you find this article interesting, give it a thumbs up. Thanks!