Home  >  Article  >  Web Front-end  >  Detailed explanation of void in JS

Detailed explanation of void in JS

小云云
小云云Original
2018-03-21 16:41:113796browse

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

javascript:void(0) meaning

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!

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