Home >Web Front-end >JS Tutorial >Another way to convert js function declaration into function expression

Another way to convert js function declaration into function expression

巴扎黑
巴扎黑Original
2016-11-25 11:11:331044browse

We know that to convert a function declaration expression into a function expression in js, you only need to add operators such as +,-,=,~ or ! or () in front of the function declaration.

In addition, you can also use the void operator for conversion. Here is a simple example:

Js code

void function(){console.log(1)}(); //1

void function(g) {console.log(g)}(this); //window

void is also commonly used in two places in project development:

1. Get the real undefined through void 0; 2. Replace a The href attribute of the element is set to javascript:void 0; to prevent page jumps.

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