Difference between using void vs wrapping in parens for IIFE void function() vs (function())

♀尐吖头ヾ 提交于 2019-12-03 12:43:36
jkdev

Well, many JavaScript programmers think void is confusing and redundant, especially Douglas Crockford who calls it one of the "Bad Parts" of JavaScript.

Preceding a function definition with void can be especially confusing. In languages like C++, it means "This is a type of function that doesn't return a value." In JavaScript, void doesn't define anything; instead it evaluates the function (or other expression) and returns the value undefined. So you don't see it much in JavaScript code.

For more info on using ! to precede modules, check out this StackOverflow answer.

Also make sure to read Ben Allman's original blog post on IIFE's.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!