! javascript中的前一个函数? [英] ! preceding function in javascript?

查看:86
本文介绍了! javascript中的前一个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

感叹号在功能之前做了什么?

我今天第一次看到这样格式化的函数:

I saw a function formatted like this today for the first time:

!function(){}();

前面的感叹号是什么?我假设它的功能与以下相同:

What is the preceding exclamation mark for? I assume it functions the same as:

(function(){})();

但是......这里发生了什么?

But... what's going on here?

推荐答案

前面的接受un-parseable语句,并允许JS引擎解析它, turn返回true。

The preceding ! takes the un-parseable statement, and allows it to to be parsed by the JS engine, which in turn returns true.

function(){}();
SyntaxError: Unexpected token (

!function(){}();
>>true

这篇关于! javascript中的前一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆