Skip to content

Commit

Permalink
add post
Browse files Browse the repository at this point in the history
  • Loading branch information
loverajoel committed Nov 4, 2020
1 parent f119383 commit d7698be
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions _posts/en/javascript/2020-11-04-what-is-a-void-operator.md
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();
```

0 comments on commit d7698be

Please sign in to comment.