Home >Web Front-end >JS Tutorial >Detailed explanation of void in JS
Chinese translation is "no type". It is commonly used in programming to declare the parameter types, return values, and pointer types in functions that define functions. The literal meaning of void is "typeless", void * is an "untyped pointer", and void * can point to any type of data. This article mainly shares with you the detailed explanation of void in JS, hoping to help everyone.
See
<a href="javascript:void(0);" /><a href="javascript:;" />
Neither of them will perform other operations when clicking the a tag, nor will they refresh the page. But I don’t know what the difference is between the two. I found out later:
Using void(0) is used to replace undefined, because undefind is not a reserved word of JS. (For reserved words and keywords, please refer to the URL: https://www.cnblogs.com/mandy-dyf/p/4547166.html)
The value of undefind may be modified in some browsers.
In fact, void(0) or void 0 returns undefined.
And all the following results are undefined:
console.log(void 0);
console.log(void(0));
console.log(void 'hello word!');
console.log(void(true));
seen
<a href="javascript:void(0);" /><a href="javascript:;" />
Neither of them will perform other operations when clicking the a label, nor will refresh page. But I don’t know what the difference is between the two. I found out later:
Using void(0) is used to replace undefined, because undefind is not a reserved word of JS. (For reserved words and keywords, please refer to the URL: https://www.cnblogs.com/mandy-dyf/p/4547166.html)
The value of undefind may be modified in some browsers.
In fact, void(0) or void 0 returns undefined.
And all the following results are undefined:
console.log(void 0); console.log(void(0)); console.log(void ‘hello word!’); console.log(void(true));
Related recommendations:
What is Javascript:void(0) in JavaScript What does it mean and how to use it?
The definition and detailed explanation of operator void(0) in Javascript
The above is the detailed content of Detailed explanation of void in JS. For more information, please follow other related articles on the PHP Chinese website!