Home >Web Front-end >JS Tutorial >Funny js trap questions_javascript skills

Funny js trap questions_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:34:581085browse

Look at the following code:

Copy code The code is as follows:

 var a = function(t) { return t; }
 (1 2).toString();
 alert(a);

What is the result?

In fact, the main problem is that there is no semicolon after the first line, so it is actually var a = function(t) { return t; }(1 2).toString();
Create variable a first , then execute the assignment statement, the anonymous function passes in parameter 1 2 for execution, returns the result .toString(), and assigns it to a.
For details on how to write function() {}(), please refer to the js namespace.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn