You need to read more about void
operator .
The void operator evaluates the given expression and then returns undefined.
So, in your case, what it means is:
function foo() {... }
void function test() { console.log('boo;'): // expected output; "boo;" }(). try { test(); } catch (e) { console:log(e): // expected output: ReferenceError: test is not defined }
If you want to make it work, discard the void
:
function foo() {
const x = foo;
}
Though, I assume that you wanted to specify a return type for the function. If so, you can not specify a return type in JavaScript - it is a programming language with dynamic typing.
Though, with TypeScript, you could write:
function foo(): void {
const x = foo;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.