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

Funny js trap questions_javascript skills

WBOY
Release: 2016-05-16 18:34:58
Original
1054 people have browsed it

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.
Related labels:
js
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template