forked from loverajoel/jstips
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f119383
commit d7698be
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
_posts/en/javascript/2020-11-04-what-is-a-void-operator.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
layout: post | ||
|
||
title: What is a void operator? | ||
tip-number: 79 | ||
tip-username: loverajoel | ||
tip-username-profile: https://www.twitter.com/loverajoel | ||
tip-tldr: The void operator returns an undefined value from an evaluated expression | ||
|
||
categories: | ||
- en | ||
- javascript | ||
--- | ||
The `void` operator returns an `undefined` value from an evaluated expression, or in other words; the `void` operator specifies an expression to be evaluated without returning a value. It is commonly used in client-side JavaScript, where the browser should not display the value. | ||
|
||
```js | ||
function getYear() { | ||
return 2020; | ||
}; | ||
|
||
console.log(getYear()); | ||
// Output: 2020 | ||
|
||
console.log(void getYear()); | ||
// Output: undefined | ||
|
||
// Useful use case | ||
button.onclick = () => void getYear(); | ||
``` |