---
title: "What is the use of void keyword in JavaScript?"  
description: "What is the use of void keyword in JavaScript?"  
author: "Anonymous User"  
published: 2021-07-20  
updated: 2023-11-29  
canonical: https://www.mindstick.com/forum/156530/what-is-the-use-of-void-keyword-in-javascript  
category: "javascript"  
tags: ["javascript", "javascript library", "void"]  
reading_time: 2 minutes  

---

# What is the use of void keyword in JavaScript?

What does the void [keyword](https://www.mindstick.com/forum/33572/sql-inner-join-keyword) do in [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)? [Define](https://yourviews.mindstick.com/audio/1110/lifestyles-choices-that-define-our-lives) with help of an example.

## Replies

### Reply by Aryan Kumar

In JavaScript, the **void** keyword is used to evaluate an expression and then return undefined. It's often used in situations where you want to ensure that a particular expression returns undefined, regardless of what the expression itself evaluates to.

Here's a simple example:

```plaintext
var result = void someFunction();
```

In this example, **someFunction()** is called, but the **void** keyword ensures that the result assigned to **result** is always **undefined**, regardless of what **someFunction()** returns.

It's important to note that using **void** in this way is not very common in modern JavaScript code. It's often considered more readable and idiomatic to explicitly set a variable to **undefined** if that's what you want. The **void** keyword is more historically used in scenarios like creating self-invoking anonymous functions:

```plaintext
void function() {
  // code here
}();
```

In this case, it ensures that the function is evaluated and returns **undefined**, and it's a way to encapsulate code without affecting the surrounding scope. However, using modern JavaScript practices, you might see other ways of achieving similar effects, like using arrow functions or IIFE (Immediately Invoked Function Expressions) without **void**.


---

Original Source: https://www.mindstick.com/forum/156530/what-is-the-use-of-void-keyword-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
